0% found this document useful (0 votes)
44 views

Chap17 Solutions

This document contains the SQL code to define object-relational structures for modeling drawings with shapes, courses and students/professors. It defines object types for various entities like Shape, Circle, Rectangle, Drawing, Course, Person, Student, Professor. It also creates tables to store objects of these types and inserts sample data.

Uploaded by

Samira cherif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Chap17 Solutions

This document contains the SQL code to define object-relational structures for modeling drawings with shapes, courses and students/professors. It defines object types for various entities like Shape, Circle, Rectangle, Drawing, Course, Person, Student, Professor. It also creates tables to store objects of these types and inserts sample data.

Uploaded by

Samira cherif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LOG660 - Base de données de haute performance

Chapitre 17: Relationnel-objet


Solutions:
QUESTION 1

Q1 a)

----------------------------
-- Effacer les types:
----------------------------
DROP TABLE Dessins;
DROP TYPE CercleType;
DROP TYPE RectangleType;
DROP TYPE DessinType;
DROP TYPE TableFormesType;
DROP TYPE FormeType;

----------------------------
-- Creation du type FORME:
----------------------------
CREATE OR REPLACE TYPE FormeType AS OBJECT
(
id INTEGER,
FINAL MAP MEMBER FUNCTION getId RETURN INTEGER,
MEMBER FUNCTION getAire RETURN FLOAT,
MEMBER FUNCTION imprimer RETURN VARCHAR2
) NOT INSTANTIABLE NOT FINAL
/

CREATE OR REPLACE TYPE BODY FormeType AS


FINAL MAP MEMBER FUNCTION getId RETURN INTEGER IS
BEGIN
RETURN SELF.id;
END;
MEMBER FUNCTION getAire RETURN FLOAT IS
BEGIN
RETURN 0;
END;
MEMBER FUNCTION imprimer RETURN VARCHAR2 IS
BEGIN
RETURN 'id:' || SELF.id;
END;
END;
/
----------------------------
-- Creation du type CERCLE:
----------------------------
CREATE OR REPLACE TYPE CercleType UNDER FormeType
(
rayon FLOAT,
OVERRIDING MEMBER FUNCTION getAire RETURN FLOAT,
OVERRIDING MEMBER FUNCTION imprimer RETURN VARCHAR2
)
/

CREATE OR REPLACE TYPE BODY CercleType AS


OVERRIDING MEMBER FUNCTION getAire RETURN FLOAT IS
BEGIN
RETURN (3.14159 * SELF.rayon * SELF.rayon);
END;
OVERRIDING MEMBER FUNCTION imprimer RETURN VARCHAR2 IS
BEGIN
RETURN (SELF AS FormeType).imprimer || ', rayon:' || SELF.rayon;
END;
END;
/

-------------------------------
-- Creation du type RECTANGLE:
-------------------------------
CREATE OR REPLACE TYPE RectangleType UNDER FormeType
(
largeur FLOAT,
hauteur FLOAT,
OVERRIDING MEMBER FUNCTION getAire RETURN FLOAT,
OVERRIDING MEMBER FUNCTION imprimer RETURN VARCHAR2
)
/

CREATE OR REPLACE TYPE BODY RectangleType AS


OVERRIDING MEMBER FUNCTION getAire RETURN FLOAT IS
BEGIN
RETURN (SELF.largeur * SELF.hauteur);
END;
OVERRIDING MEMBER FUNCTION imprimer RETURN VARCHAR2 IS
BEGIN
RETURN (SELF AS FormeType).imprimer ||
', largeur:' || SELF.largeur ||
', hauteur:' || SELF.hauteur;
END;
END;
/
-------------------------------
-- Creation du type DESSIN:
-------------------------------
CREATE OR REPLACE TYPE TableFormesType AS TABLE OF FormeType
/

CREATE TYPE DessinType AS OBJECT


(
titre VARCHAR2(50),
formes TableFormesType
)
/

-----------------------------------------
-- Creation d'une table d'objets Dessin:
-----------------------------------------
CREATE TABLE Dessins OF DessinType
(
PRIMARY KEY(titre)
)
NESTED TABLE formes STORE AS laTableDeFormes
/

commit
/

Q1 b)

INSERT INTO Dessins VALUES


(
'mon dessin',
TableFormesType(CercleType(1,10), RectangleType(2,5,20))
)

Q1 c)

----------------------------------------------------------
-- Affichage de l'aire des formes du dessin 'mon dessin':
----------------------------------------------------------

SELECT F.id, F.getAire() FROM TABLE(


SELECT D.formes FROM Dessins D
WHERE D.titre = 'mon dessin') F;

-----------------------------------------------------------
-- Affichage de l'aire des cercles du dessin 'mon dessin':
-----------------------------------------------------------

SELECT F.id, F.getAire() FROM TABLE(


SELECT D.formes FROM Dessins D
WHERE D.titre = 'mon dessin') F
WHERE VALUE(F) IS OF TYPE (CercleType);
QUESTION 2

Q2 a)

DROP TABLE Cours;


DROP TABLE Professeurs;
DROP TABLE Étudiants;
DROP TYPE ProfesseurType;
DROP TYPE ÉtudiantType;
DROP TYPE PersonneType;
DROP TYPE TableCoursRefType;
DROP TYPE TableRésultatsType;
DROP TYPE RésultatType;
DROP TYPE CoursRefType;
DROP TYPE CoursType;

----------------------------
-- Creation du type COURS:
----------------------------
CREATE OR REPLACE TYPE CoursType AS OBJECT
(
sigle VARCHAR2(6),
titre VARCHAR2(50),
année INTEGER,
"session" VARCHAR(1)
)
/

CREATE OR REPLACE TYPE CoursRefType AS OBJECT


(coursRef REF CoursType)
/

CREATE OR REPLACE TYPE TableCoursRefType AS


TABLE OF CoursRefType;
/

----------------------------
-- Creation du type PERSONNE:
----------------------------
CREATE OR REPLACE TYPE PersonneType AS OBJECT
(
nom VARCHAR2(50),
courriel VARCHAR2(50),
dateNaissance DATE,
FINAL MEMBER FUNCTION getAge RETURN INTEGER
) NOT INSTANTIABLE NOT FINAL
/

CREATE OR REPLACE TYPE BODY PersonneType AS


FINAL MEMBER FUNCTION getAge RETURN INTEGER IS
BEGIN
RETURN TRUNC(MONTHS_BETWEEN(SYSDATE, SELF.dateNaissance)/12);
END;
END;
/
----------------------------
-- Creation du type RESULTAT:
----------------------------
CREATE OR REPLACE TYPE RésultatType AS OBJECT
(
note INTEGER,
coursRef CoursRefType
)
/

CREATE OR REPLACE TYPE TableRésultatsType AS TABLE OF RésultatType;


/

----------------------------
-- Creation du type ETUDIANT:
----------------------------
CREATE OR REPLACE TYPE ÉtudiantType UNDER PersonneType
(
codePermanent VARCHAR2(15),
programme VARCHAR2(15),
coursSuivis TableRésultatsType,
FINAL MEMBER FUNCTION getMoyenne(
p_année INTEGER,
p_session VARCHAR2
) RETURN FLOAT
)
/

CREATE OR REPLACE TYPE BODY ÉtudiantType AS


FINAL MEMBER FUNCTION getMoyenne(
p_année INTEGER,
p_session VARCHAR2
) RETURN FLOAT IS
moy FLOAT;
BEGIN
SELECT AVG(R.note) into moy
FROM TABLE(SELF.coursSuivis) R
WHERE R.coursRef.coursRef.année = p_année AND
R.coursRef.coursRef."session" = p_session;
RETURN moy;
END;
END;
/

----------------------------
-- Creation du type PROFESSEUR:
----------------------------
CREATE OR REPLACE TYPE ProfesseurType UNDER PersonneType
(
matricule VARCHAR2(8),
département VARCHAR2(30),
coursEnseignés TableCoursRefType,
FINAL MEMBER FUNCTION getChargeEnseignement RETURN INTEGER
)
/
CREATE OR REPLACE TYPE BODY ProfesseurType AS
FINAL MEMBER FUNCTION getChargeEnseignement RETURN INTEGER IS
num INTEGER;
BEGIN
SELECT COUNT(*) INTO num
FROM TABLE(SELF.coursEnseignés);
RETURN num;
END;
END;
/

--------------------------------
-- Creation des tables d’objets:
--------------------------------

CREATE TABLE Cours OF CoursType


(
PRIMARY KEY(sigle),
CONSTRAINT ctrSessionValide CHECK("session" IN ('A','H','E'))
)
/

CREATE TABLE Professeurs OF ProfesseurType


(
PRIMARY KEY (matricule),
UNIQUE (courriel)
)
NESTED TABLE coursEnseignés STORE AS LesCoursEnseignés
/

CREATE TABLE Étudiants OF ÉtudiantType


(
PRIMARY KEY (codePermanent),
UNIQUE (courriel)
)
NESTED TABLE coursSuivis STORE AS LesCoursSuivis
/

commit
/
Q2 b)

INSERT INTO Cours VALUES


(CoursType(
'LOG660',
'Bases de données de haute performance',
2010,
'E'))
/

INSERT INTO Professeurs


SELECT ProfesseurType(
'Jean Seigne',
'[email protected]',
TO_DATE('24/06/1960','DD/MM/YYYY'),
'12345678',
'Génie logiciel et des TI',
TableCoursRefType(CoursRefType(REF(C)))
)
FROM Cours C
WHERE C.sigle = 'LOG660';
/

INSERT INTO Étudiants


SELECT ÉtudiantType(
'Paul Temps',
'[email protected]',
TO_DATE('01/04/1985','DD/MM/YYYY'),
'TEMP12345678',
'Génie logiciel',
TableRésultatsType(RésultatType(60,CoursRefType(REF(C)))))
FROM Cours C
WHERE C.sigle = 'LOG660';
/

commit
/

Q2 c)

SELECT E.nom, E.getAge() as age, E.getMoyenne(2010,’E’) as moyE10


FROM Étudiants E;

Q2 d)

SELECT T.coursRef.sigle, T.coursRef.titre


FROM TABLE(
SELECT P.coursSuivis from Professeurs P
WHERE UPPER(P.nom) like '%SEIGNE'
) T;

You might also like