ORACLE PL/SQL Prozeduren erstellen.


R3LLiK

Grünschnabel
#1
Hallo Leute,
Ich stehe vor ein Problem ich will eine prozedur erstellen, dass mir einen neuen benutzer(blut spender) anlegt, in der prozedur soll der name und die adresse abgefragt werden, wenn es den benutzer noch nicht gibt soll er angelegt werden ansonsten soll eine meldung erscheinen spender schon in der datenbank.

Code:
DROP Table Person cascade constraints;
DROP Table Adresse cascade constraints;
DROP Table Laborant cascade constraints;
DROP Table Sanitäter cascade constraints;
DROP Table Arzt cascade constraints;
DROP Table Spender cascade constraints;
DROP Table Labor cascade constraints;
DROP Table Blutspendeeinheit cascade constraints;
DROP Table Blutkonserven cascade constraints;
DROP Table Blutspendezentrum cascade constraints;
DROP Table Blutspendedienst cascade constraints;
DROP Table Mahlzeit cascade constraints;
DROP Table Zutat cascade constraints;
DROP Table Gericht cascade constraints;
DROP TABLE Spenderbesuch cascade constraints;

DROP VIEW Spender_Info cascade constraints;

DROP SEQUENCE Adress_pk;
DROP SEQUENCE Person_pk;
DROP SEQUENCE Labor_pk;
DROP SEQUENCE Laborant_pk;
DROP SEQUENCE Sani_pk;
DROP SEQUENCE Arzt_pk;
DROP SEQUENCE Mahlzeit_pk;
DROP SEQUENCE Zutat_pk;
DROP SEQUENCE Gericht_pk;
DROP SEQUENCE Spender_pk;
DROP SEQUENCE Blutspendeeinheit_pk;
DROP SEQUENCE Blutspendedienst_pk;
DROP SEQUENCE Blutspendezentrum_pk;
DROP SEQUENCE Spenderbesuch_pk;


CREATE SEQUENCE Adress_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Person_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Labor_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Laborant_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Sani_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Arzt_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Mahlzeit_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Zutat_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Gericht_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Spender_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Blutspendeeinheit_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Blutspendedienst_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Blutspendezentrum_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;
CREATE SEQUENCE Spenderbesuch_pk INCREMENT BY 1  START WITH 1  NOMAXVALUE  NOCYCLE CACHE 10000;







CREATE Table Adresse (
Adress_ID INTEGER DEFAULT Adress_pk.nextval NOT NULL,
Strasse VARCHAR2(50)NOT NULL,
HNR VARCHAR2(5) NOT NULL,
PLZ VARCHAR2(10) NOT NULL,
Ort VARCHAR2(50) NOT NULL,
PRIMARY KEY(Adress_ID)

);

CREATE Table Person (
Person_ID INTEGER DEFAULT Person_pk.nextval NOT NULL,
Adress_ID INTEGER NOT NULL,
Titel VARCHAR2(10)  ,
Nachname VARCHAR2(40) NOT NULL ,
Vorname VARCHAR2(40) NOT NULL,
Geb_Datum DATE  NOT NULL ,
PRIMARY KEY (Person_ID)



); 

CREATE Table Labor (
Labor_ID INTEGER DEFAULT Labor_pk.nextval NOT NULL,
gelagerteKonserven INTEGER NOT NULL,
PRIMARY KEY (Labor_ID)

);


CREATE Table Laborant(
Laborant_ID INTEGER DEFAULT Laborant_pk.nextval NOT NULL,
Labor_ID INTEGER NOT NULL,
Person_ID INTEGER NOT NULL,
PRIMARY KEY (Laborant_ID)



);

CREATE Table Sanitäter(
Sanitäter_ID INTEGER DEFAULT Sani_pk.nextval NOT NULL,
Person_ID INTEGER NOT NULL,
Zuständigkeit VARCHAR2(100) NOT NULL,
PRIMARY KEY(Sanitäter_ID)

);

CREATE Table Arzt (
Arzt_ID INTEGER DEFAULT Arzt_pk.nextval NOT NULL,
Person_ID INTEGER NOT NULL,
Anzahl_untersuchter_Spender INTEGER NOT NULL,
PRIMARY KEY (Arzt_ID)


);



CREATE Table Mahlzeit (
Mahlzeit_ID INTEGER  DEFAULT Mahlzeit_pk.nextval NOT NULL,
Bezeichnung VARCHAR2(200) NOT NULL,
Ernährungsform VARCHAR2(200) NOT NULL,
Eisengehalt_mg VARCHAR2(10) NOT NULL,
PRIMARY KEY (Mahlzeit_ID)


);

CREATE Table Zutat (
Zutat_ID INTEGER DEFAULT Zutat_pk.nextval NOT NULL,
Einzelkosten NUMBER(5),
Bezeichnung VARCHAR2(200),
PRIMARY KEY (Zutat_ID)
);

CREATE Table Gericht (
Mahlzeit_ID INTEGER DEFAULT Gericht_pk.nextval NOT NULL,
Zutat_ID INTEGER NOT NULL,
PRIMARY KEY (Mahlzeit_ID,Zutat_ID)

);

CREATE Table Spender (
Spender_ID INTEGER DEFAULT Spender_pk.nextval NOT NULL,
Person_ID INTEGER ,
Blutgruppe VARCHAR2(5) CHECK (Blutgruppe IN('ABp','Bp','Ap','0p','ABn','Bn','An','0n')),
Rhesusfaktor INTEGER  NOT NULL,
Email varchar2(30) NOT NULL ,
Auszeichnung Varchar2(50),
Anmerkung Varchar2(500),
PRIMARY KEY (Spender_ID)
);


CREATE Table Spenderbesuch (
Spenderbesuch_ID INTEGER DEFAULT Spenderbesuch_pk.nextval NOT NULL,
Spender_ID INTEGER NOT NULL,
Arzt_ID INTEGER NOT NULL,
Sanitäter_ID INTEGER NOT NULL,
Mahlzeit_ID INTEGER NOT NULL,
BS_Einheit_ID INTEGER NOT NULL,
SpendeDatum DATE NOT NULL,
Hämoglobinwert NUMBER NOT NULL,
GewichtinKG INTEGER NOT NULL,
KörpertemparaturinC INTEGER NOT NULL,
Puls INTEGER NOT NULL,
Systolischer_Blutdruck INTEGER NOT NULL,
Diastolischer_Blutdruck INTEGER NOT NULL,
PRIMARY KEY(Spenderbesuch_ID)
);

CREATE Table Blutspendeeinheit (
BS_Einheit_ID INTEGER DEFAULT Blutspendeeinheit_pk.nextval NOT NULL,
Anzahl_Liegen INTEGER NOT NULL,
PRIMARY KEY (BS_Einheit_ID)

);






CREATE Table Blutspendedienst (
BS_Dienst_ID INTEGER DEFAULT Blutspendedienst_pk.nextval NOT NULL,
Bezeichnung VARCHAR2(100) NOT NULL,
Anzahl_Spender INTEGER NOT NULL,
PRIMARY KEY (BS_Dienst_ID)

);

CREATE Table Blutspendezentrum (
BS_Zentrum_ID INTEGER DEFAULT Blutspendezentrum_pk.nextval NOT NULL,
Bezeichnung VARCHAR2(200) NOT NULL,
PRIMARY KEY (BS_Zentrum_ID)
);


CREATE Table Blutkonserven (
Eurocode_IBLS VARCHAR2(100) NOT NULL,
Spenderbesuch_ID INTEGER NOT NULL,
Labor_ID INTEGER NOT NULL,
BS_Zentrum_ID INTEGER NOT NULL,
Verkehrsfähig NUMBER(1) NOT NULL,
Haltbarkeit DATE NOT NULL,
Blutgruppe VARCHAR2(5) NOT NULL CHECK (Blutgruppe IN('ABp','Bp','Ap','0p','ABn','Bn','An','0n')),
PRIMARY KEY(Eurocode_IBLS)



);



ALTER TABLE Person
ADD CONSTRAINT per_fk
FOREIGN KEY(Adress_ID) REFERENCES Adresse(Adress_ID)
 ON DELETE CASCADE;

ALTER TABLE Spender
ADD CONSTRAINT spe_fk
FOREIGN KEY (Person_ID) REFERENCES Person(Person_ID)
 ON DELETE CASCADE;

ALTER TABLE Laborant
ADD CONSTRAINT lab_fk
FOREIGN KEY (Person_ID) REFERENCES Person(Person_ID)
 ON DELETE CASCADE;

ALTER TABLE Laborant
ADD CONSTRAINT labo_fk
FOREIGN KEY (Labor_ID) REFERENCES Labor(Labor_ID)
;

ALTER TABLE Sanitäter
ADD CONSTRAINT San_fk
FOREIGN KEY (Person_ID) REFERENCES Person(Person_ID)
 ON DELETE CASCADE;

ALTER TABLE Arzt
ADD CONSTRAINT Arzt_fk
FOREIGN KEY (Person_ID) REFERENCES Person(Person_ID)
;

ALTER TABLE Gericht
ADD CONSTRAINT Gericht_fk
FOREIGN KEY (Zutat_ID) REFERENCES Zutat(Zutat_ID)
;

ALTER TABLE Gericht
ADD CONSTRAINT Gerich_fk
FOREIGN KEY (Mahlzeit_ID) REFERENCES Mahlzeit(Mahlzeit_ID)
 ON DELETE CASCADE;

ALTER TABLE Spenderbesuch
ADD CONSTRAINT spender_fk
FOREIGN KEY (Spender_ID) REFERENCES Spender(Spender_ID)
;

ALTER TABLE Spenderbesuch
ADD CONSTRAINT mahlzeit_fk
FOREIGN KEY (Mahlzeit_ID) REFERENCES Mahlzeit(Mahlzeit_ID);

ALTER TABLE Spenderbesuch
ADD CONSTRAINT arspe_fk
FOREIGN KEY (Arzt_ID) REFERENCES Arzt(Arzt_ID)
 ON DELETE CASCADE;

ALTER TABLE Spenderbesuch
ADD CONSTRAINT sanitäter_fk
FOREIGN KEY (Sanitäter_ID) REFERENCES Sanitäter(Sanitäter_ID)
 ON DELETE CASCADE;

ALTER TABLE Spenderbesuch
ADD CONSTRAINT bseinheit_fk
FOREIGN KEY (BS_Einheit_ID) REFERENCES Blutspendeeinheit(BS_Einheit_ID)
 ON DELETE CASCADE;


 
ALTER TABLE Blutkonserven
ADD CONSTRAINT bsze_fk
FOREIGN KEY (BS_Zentrum_ID) REFERENCES Blutspendezentrum(BS_Zentrum_ID)
 ON DELETE CASCADE;

ALTER TABLE Blutkonserven
ADD CONSTRAINT blulab_fk
FOREIGN KEY (Labor_ID) REFERENCES Labor(Labor_ID)
 ON DELETE CASCADE;

ALTER TABLE Blutkonserven
ADD CONSTRAINT bluspe_fk
FOREIGN KEY (Spenderbesuch_ID) REFERENCES Spenderbesuch(Spenderbesuch_ID)
 ON DELETE CASCADE;



 

INSERT INTO Adresse values(Adress_pk.NEXTVAL,'bla','3a','53636','blabla');
INSERT INTO Person values(Person_pk.nextval,1,'Dr','Mundo','Mundo',TO_DATE('15.06.2000', 'DD.MM.YYYY'));
INSERT INTO Person values(Person_pk.nextval,1,'Streamer','anni','anney',TO_DATE('07.10.1995', 'DD.MM.YYYY'));
INSERT INTO Person values(Person_pk.nextval,1,'Adc','rob','Forti',TO_DATE('15.10.2006', 'DD.MM.YYYY'));
INSERT INTO Person values(Person_pk.nextval,1,'Renn','Dominik','Margull',TO_DATE('12.07.1980', 'DD.MM.YYYY'));
INSERT INTO Arzt values(Arzt_pk.nextval,1,30);
INSERT INTO Spender values(Spender_pk.nextval,2,'ABp',10,'Anni.anney@gmail.com','Gold','nett');
INSERT INTO Sanitäter values(Sani_pk.nextval,3,'Essen bringen');
INSERT INTO Labor values(Labor_pk.nextval,5);
INSERT INTO Labor values(Labor_pk.nextval,5);
INSERT INTO Labor values(Labor_pk.nextval,3);
INSERT INTO Labor values(Labor_pk.nextval,5);
INSERT INTO Labor values(Labor_pk.nextval,5);
INSERT INTO Laborant values(Laborant_pk.nextval,1,4);
INSERT INTO Mahlzeit values(Mahlzeit_pk.nextval,'Apfel','Gesund','warum');
INSERT INTO Blutspendeeinheit values(Blutspendeeinheit_pk.nextval,10);
INSERT INTO Spenderbesuch values(Spenderbesuch_pk.nextval,1,1,1,1,1,TO_DATE('26.04.2019', 'DD.MM.YYYY'),1,60,37,60,120,70);
INSERT INTO Blutspendezentrum values(Blutspendezentrum_pk.nextval,'affe');
INSERT INTO Blutkonserven values('var',1,1,1,1,TO_DATE('26.04.2020', 'DD.MM.YYYY'),'ABp');
INSERT INTO Blutkonserven values('vlla',1,1,1,1,TO_DATE('10.04.2019', 'DD.MM.YYYY'),'ABp');
INSERT INTO Blutkonserven values('vadr',1,1,1,1,TO_DATE('26.08.2019', 'DD.MM.YYYY'),'ABp');
INSERT INTO Blutkonserven values('verr',1,1,1,1,TO_DATE('26.10.2018', 'DD.MM.YYYY'),'ABn');
so sieht meine db aus mit den tabellen
 

Neue Beiträge