Commit 442d6d0b authored by Xiang Li's avatar Xiang Li
Browse files

Update RO_2.sql

parent 9e268604
DECLARE
RefClasse1 REF TClasse;
RefClasse2 REF TClasse;
RefEspece1 REF TEspece;
RefEspece2 REF TEspece;
RefMedicament1 REF TMedicament;
RefMedicament2 REF TMedicament;
RefTraitement1 REF TTraitement;
RefTraitement2 REF TTraitement;
RefTraitement3 REF TTraitement;
BEGIN
INSERT INTO Classe (nom) VALUES ('mammifere');
INSERT INTO Classe (nom) VALUES ('reptile');
--init RefClasse1
SELECT REF(C) INTO RefClasse1 FROM Classe C WHERE nom='mammifere';
SELECT REF(C) INTO RefClasse2 FROM Classe C WHERE nom='reptile';
INSERT INTO Espece VALUES ('chien', RefClasse1);
INSERT INTO Espece VALUES ('chat', RefClasse1);
CREATE OR REPLACE TYPE TClasse AS OBJECT (
nom VARCHAR(50)
);
/
CREATE TABLE Classe OF Tclasse (
PRIMARY KEY (nom)
);
/
SELECT REF(E) INTO RefEspece1 FROM Espece E WHERE nom='chien';
SELECT REF(E) INTO RefEspece2 FROM Espece E WHERE nom='chat';
CREATE OR REPLACE TYPE TEspece AS OBJECT(
nom VARCHAR(50),
classe REF TClasse
);
/
CREATE TABLE Espece OF TEspece (
PRIMARY KEY (nom),
SCOPE FOR (classe) IS Classe
);
/
CREATE OR REPLACE TYPE TRefEspece AS OBJECT(espece REF TEspece);
/
CREATE TABLE RefEspece OF TRefEspece( SCOPE FOR (espece) IS Espece);
/
CREATE OR REPLACE TYPE ListRefEspece AS TABLE OF TRefEspece;
/
INSERT INTO Medicament VALUES ('BHRG', 'anti puce', (ListRefEspece(RefEspece1, RefEspece2)));
INSERT INTO Medicament VALUES ('KHFG', 'calmant', (ListRefEspece(RefEspece1)));
SELECT REF(M) INTO RefMedicament1 FROM Medicament M WHERE nomMolecule='BHRG';
SELECT REF(M) INTO RefMedicament2 FROM Medicament M WHERE nomMolecule='KHFG';
------------------------------------------------------
INSERT INTO Taitement VALUES
(
1, 'traitement total', TO_DATE('2019-06-10','YYYY-MM-DD'),5,
ListPrescription(
TPrescription(RefMedicament1, 2),
TPrescription(RefMedicament2, 1)
)
CREATE OR REPLACE TYPE TMedicament AS OBJECT(
nomMolecule VARCHAR(50),
effets VARCHAR(255),
especes ListRefEspece
);
INSERT INTO Taitement VALUES
(
2, 'traitement calmant', TO_DATE('2019-06-10','YYYY-MM-DD'),3,
ListPrescription(TPrescription(RefMedicament2, 1 ))
/
CREATE TABLE Medicament OF TMedicament(
PRIMARY KEY (nomMolecule),
effets NOT NULL
) NESTED TABLE especes STORE AS NT_Medicament_Especes;
/
CREATE OR REPLACE TYPE TPrescription AS OBJECT(
medicament REF TMedicament,
quantiteJour integer
);
INSERT INTO Taitement VALUES
(
3, 'traitement anti puce', TO_DATE('2019-06-10','YYYY-MM-DD'),4,
ListPrescription(TPrescription(RefMedicament1, 2 ))
/
CREATE TABLE Prescription OF TPrescription(
quantiteJour NOT NULL,
CHECK(quantiteJour > 0),
SCOPE FOR (medicament) IS Medicament
);
--Init RefTraitement1 & RefTraitement2 & RefTraitement3
SELECT REF(T) INTO RefTraitement1 FROM Traitement T WHERE id=1;
SELECT REF(T) INTO RefTraitement2 FROM Traitement T WHERE id=2;
SELECT REF(T) INTO RefTraitement3 FROM Traitement T WHERE id=3;
INSERT INTO Clients VALUES
(
1, 0789653214, 'bond', 'james', TO_DATE('1985-01-12', 'YYYY-MM-DD'), '150 avenue de Paris'
/
CREATE OR REPLACE TYPE ListPrescription AS TABLE OF TPrescription;
/
------------------------------------------------------
CREATE OR REPLACE TYPE TTraitement AS OBJECT(
id integer,
nom varchar2(255),
debut date,
duree integer,
prescriptions ListPrescription
);
INSERT INTO Animaux VALUES
(
1,'lechien', 15, 30, TO_DATE('1999-01-12', 'YYYY-MM-DD'), RefEspece1,
ListRefTraitement(TRefTraitement(RefTraitement1), TRefTraitement(RefTraitement2))
);
INSERT INTO Animaux VALUES
(
2,'lechat', 12, 10, TO_DATE('1999-01-12', 'YYYY-MM-DD'), RefEspece2, ListRefTraitement(TRefTraitement(RefTraitement3))
/
CREATE TABLE Traitement OF TTraitement(
PRIMARY KEY (id),
nom NOT NULL,
debut NOT NULL,
duree NOT NULL,
CHECK (duree > 0)
) NESTED TABLE prescriptions STORE AS NT_Traitement_Prescriptions;
CREATE OR REPLACE TYPE TRefTraitement AS OBJECT(traitement REF TTraitement);
/
CREATE TABLE RefTraitement OF TRefTraitement( SCOPE FOR (traitement) IS Traitement);
/
CREATE OR REPLACE TYPE ListRefTraitement AS TABLE OF TRefTraitement;
/
----------------------------------------------------------------
CREATE OR REPLACE TYPE TClients AS OBJECT (
id INTEGER,
telephone INTEGER,
nom VARCHAR(50),
prenom VARCHAR(50),
date_naissance DATE,
adresse VARCHAR(255)
);
INSERT INTO Veterinaires VALUES
(1, '0616814835', 'Martin', 'John', '1970-01-20', '10 rue Saint Anne 75009 Paris', RefClasse1,
ListRefTraitement(TRefTraitement(RefTraitement1), TRefTraitement(RefTraitement2))
CREATE TABLE Clients OF TCLients(
PRIMARY KEY (id),
telephone NOT NULL,
nom NOT NULL,
prenom NOT NULL,
date_naissance NOT NULL,
adresse NOT NULL,
CHECK (telephone > 100000000 AND telephone < 999999999)
);
INSERT INTO Veterinaires VALUES
(1, '0616814835', 'Anna', 'Alston', '1980-01-20', '10 rue De gaule 75009 Paris', RefClasse1,
ListRefTraitement(TRefTraitement(RefTraitement3))
/
CREATE OR REPLACE TYPE TAnimal AS OBJECT (
id INTEGER,
nom VARCHAR(30),
dernierPoids INTEGER,
derniereTaille INTEGER,
date_naissance INTEGER,
espece REF TEspece,
traitements ListRefTraitement,
client REF TClients
);
/
CREATE TABLE Animal OF TAnimal(
nom NOT NULL,
dernierPoids NOT NULL,
derniereTaille NOT NULL,
date_naissance NOT NULL,
PRIMARY KEY (id),
CHECK (dernierPoids > 0),
CHECK (derniereTaille > 0),
client NOT NULL,
SCOPE FOR (client) IS Clients,
espece NOT NULL,
SCOPE FOR (espece) IS Espece
) NESTED TABLE traitements STORE AS NT_Animal_Traitements;
/
CREATE TABLE Veterinaires(
id INTEGER,
telephone INTEGER NOT NULL,
nom VARCHAR(50) NOT NULL,
prenom VARCHAR(50) NOT NULL,
date_naissance DATE NOT NULL,
adresse VARCHAR(255) NOT NULL,
specialite REF TClasse NOT NULL,
traitements ListRefTraitement,
PRIMARY KEY (id),
CHECK (telephone > 100000000 AND telephone < 999999999),
SCOPE FOR (specialite) IS Classe
) NESTED TABLE traitements STORE AS NT_Veterinaire_Traitements;
/
CREATE TABLE Assistants(
id INTEGER,
telephone INTEGER NOT NULL,
nom VARCHAR(50) NOT NULL,
prenom VARCHAR(50) NOT NULL,
date_naissance DATE NOT NULL,
adresse VARCHAR(255) NOT NULL,
specialite REF TClasse NOT NULL,
PRIMARY KEY (id),
CHECK (telephone > 100000000 AND telephone < 999999999),
SCOPE FOR (specialite) IS Classe
);
INSERT INTO Assistants VALUES
(3, '0616445424', 'Dubois', 'Thomas', '1980-08-10', '15 faubourg Saint Martin 75010 Paris', RefClasse1);
INSERT INTO Assistants VALUES
(4, '0854345689', 'Picard', 'Jacques', '1920-12-12', '19 rue Saint Gervais 60700 Pontpoint', RefClasse1);
END;
/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment