Sie sind auf Seite 1von 5

/*******************Cration des types***************************/ CREATE TYPE telephone_elt_vry_type AS OBJECT (numTel VARCHAR2(14)); CREATE TYPE telephone_vry_type AS VARRAY(3) OF telephone_elt_vry_type; CREATE

TYPE client_type AS OBJECT (num NUMBER(6), nom VARCHAR2(30), adresse VARC HAR2(40), telephone_vry telephone_vry_type); CREATE TYPE compte_type AS OBJECT (nCompte VARCHAR2(5), solde NUMBER(10,2), dateOuv DATE, ref_Client REF client_type) NOT FINAL NOT INSTANTIABLE; CREATE TYPE signataire_elt_nt_type AS OBJECT (num NUMBER(5), droit CHAR(1)); CREATE TYPE signataire_nt_type AS TABLE OF signataire_elt_nt_type; CREATE TYPE cptCourant_type UNDER compte_type (nbOpCB NUMBER(5), signataire_nt signataire_nt_type); CREATE TYPE cptEpargne_type UNDER compte_type (txInt NUMBER(2,1)); CREATE TYPE mouvement_type AS OBJECT (ref_Client REF client_type, ref_CptCourant REF cptCourant_type, dateOp DATE, montant NUMBER(8,2)); select * from USER_TYPES; select * from USER_TYPE_ATTRS; /***********************Cration des Tables*************************/ CREATE TABLE Client OF client_type (CONSTRAINT pk_client PRIMARY KEY (num)); CREATE TABLE CptCourant OF cptCourant_type (CONSTRAINT pk_cptCourant PRIMARY KEY (nCompte), CONSTRAINT nn_Courant_ref_Client CHECK (ref_Client IS NOT NULL), CONSTRAINT refer_Courant_Client ref_Client REFERENCES Client) NESTED TABLE signataire_nt STORE AS signataire_tabnt; ALTER TABLE signataire_tabnt ADD CONSTRAINT ck_droit CHECK (droit IN ('X','R','D')); ALTER TABLE signataire_tabnt ADD CONSTRAINT nn_signataire_num CHECK (num IS NOT NULL); ALTER TABLE signataire_tabnt ADD CONSTRAINT nn_signataire_droit CHECK (droit IS NOT NULL); CREATE TABLE CptEpargne OF cptEpargne_type (CONSTRAINT pk_cptEpargne PRIMARY KEY (nCompte), CONSTRAINT nn_Epargne_ref_Client CHECK (ref_Client IS NOT NULL), CONSTRAINT refer_Epargne_Client ref_Client REFERENCES Client, CONSTRAINT ck_txInt CHECK (txInt < 3.5)); CREATE TABLE Mouvement OF mouvement_type (CONSTRAINT refer_Mvt_Client ref_Client REFERENCES Client,

CONSTRAINT CONSTRAINT CONSTRAINT CONSTRAINT

nn_Mvt_ref_Client CHECK (ref_Client IS NOT NULL), refer_Mvt_CptCourant ref_CptCourant REFERENCES CptCourant, nn_Mvt_ref_CptCourant CHECK (ref_CptCourant IS NOT NULL), df_dateOp dateOp DEFAULT (SYSDATE-2) );

select * from USER_OBJECT_TABLES; /**************************Insertion des tuples**********************/ INSERT INTO Client VALUES (client_type(12599, 'Gharbi Mohamed', '24 Bardo 2000', telephone_vry_type(telephone_elt_vry_type('98222999'), telephone_elt_vry_type('71235999'),telephone_elt_vry_type('70234000')) )); INSERT INTO Client VALUES (client_type(10987, 'Houda Jribi', '5 Tunis 1087 ', telephone_vry_type(telephone_elt_vry_type('22555999'), telephone_elt_vry_type('71555999'),telephone_elt_vry_type('70666999')) )); /********Nous allons maintenant insrer les tuples de la table compte courant en i nitialisant la table signataire vide. */ INSERT INTO CptCourant VALUES (cptCourant_type('CC2', 4030, '12/01/2000', (SELECT REF(cli) FROM Client cli WHERE cli.num = 12599), 509, signataire_nt_type()) ); INSERT INTO CptCourant VALUES (cptCourant_type('CC2', 206, '13/12/2008', (SELECT REF(cli) FROM Client cli WHERE cli.num = 10987), 304, signataire_nt_type()) ); INSERT INTO CptCourant VALUES (cptCourant_type('CC3', 387, '10/06/2010', (SELECT REF(cli) FROM Client cli WHERE cli.num = 10987), 200, signataire_nt_type(signataire_elt_nt_type(2,'R'), signataire_elt_nt_type(3,'X')) ) ); /******Nous allons mnt remplir la table signataire */ INSERT INTO TABLE (SELECT signataire_nt FROM CptCourant WHERE nCompte = 'CC2') VALUES (signataire_elt_nt_type(2,'D')); INSERT INTO TABLE (SELECT signataire_nt FROM CptCourant WHERE nCompte = 'CC2') VALUES (signataire_elt_nt_type(2,'R')); INSERT INTO TABLE (SELECT signataire_nt FROM CptCourant WHERE nCompte = 'CC1') VALUES (signataire_elt_nt_type(5,'D')); /**********Insertion table cptepargne */ INSERT INTO CptEpargne VALUES (cptEpargne_type('CE1', 600, '05-02-1965',

(SELECT REF(cli) FROM Client cli WHERE cli.num = 12599), 2.7 )); /***********Insertion mouvment*/ INSERT INTO mouvement VALUES (mouvement_type( (SELECT REF(cli) FROM Client cli WHERE cli.num = 12599), (SELECT REF(cou) FROM CptCourant cou WHERE cou.nCompte = 'CC1'), SYSDATE-7, 100) ); INSERT INTO mouvement VALUES (mouvement_type( (SELECT REF(cli) FROM Client cli WHERE cli.num =10987), (SELECT REF(cou) FROM CptCourant cou WHERE cou.nCompte = 'CC1'), SYSDATE-7, -65) ); /********************Mise jour**********************************/ UPDATE Client c SET c.nom='Houda Jribi Masmoudi' WHERE c.num=10987; UPDATE Client c SET c.telephone_vry=telephone_vry_type(telephone_elt_vry_type('71777888'), telephone_elt_vry_type('23333222'),telephone_elt_vry_type('31555222')) WHERE c. num=12599; UPDATE THE (SELECT e.signataire_nt FROM CptCourant e WHERE e.nCompte='CC2') a SET a.droit = 'X' WHERE a.num=2; /* Supression d'un client se fait avec une procdure. Cet exxercice sera report pour l a sance prochaine. Mais essayons de supprimer juste un compte num='CC3' */ Delete From CptCourant e where e.nCompte='CC3';

/********************************SELECTION********************/ select e.num,e.nom,e.adresse from client e; ////// select cc.ncompte,cc.solde,To_Char(cc.dateouv,'DD\MM\YYYY'),cc.ref_client.num from CPTCOURANT cc union select ce.ncompte,ce.solde,To_Char(ce.dateouv,'DD\MM\YYYY'),ce.ref_client.num from CPTEPARGNE ce; ///// select count(c.num) from client c; //////// 4) select cc.ncompte,ce.ncompte from CPTCOURANT cc,CPTEPARGNE ce where cc.ref_client.nom='Gharbi Mohamed' or ce.ref_client.nom='Gharbi Mohamed'

; ////// 5) select cc.ncompte,cc.ref_client.nom,cc.solde from CPTCOURANT cc where cc.solde<400 ; /////// 6) select cp.ref_client.num,cp.ref_client.nom,cp.ref_client.adresse from CptEpargne cp group by cp.ref_client.num,cp.ref_client.nom,cp.ref_client.adresse having count(cp.ncompte)=1; ////////// 7) select cp.ref_client.num,cp.ref_client.nom,cp.ref_client.adresse from CptEpargne cp group by (cp.ref_client.num,cp.ref_client.nom,cp.ref_client.adresse) having count(cp.ncompte) = (select max (count(cp2.ref_client.num)) from CptEpargne cp2 group by (cp2.ref_client.num)); //////// 8) 9) select count (numTel ) from table(select c.telephone_vry from client c where c. nom='Gharbi Mohamed'); //// 11) /////TP3 1) Declare nouvtel TELEPHONE_VRY_TYPE; Begin select c.telephone_vry into nouvtel from client c where c.nom='Gharbi Mohamed'; if(nouvtel(2) IS NULL ) then DBMS_OutPut.Put_Line('num inexistant'); else DBMS_OutPut.Put_Line(nouvtel(2).numTel); End if; end; 2) alter type CLIENT_TYPE add member function nbcepargne return number cascade; // create or replace type body CLIENT_TYPE as member function nbcepargne return number is begin select count(*) into res from CPTEPARGNE e where e.REF_CLIENT.NUM=self.NUM; return res; end nbcepargne; 3) create or replace type body CPTCOURANT_TYPE as member function nbsignataire return number is

res number; begin select count(distinct (ant.num)) into res from table(select cpt.SIGNATAIRE_NT f rom CPTCOURANT cpt where cpt.ncompte=self.ncompte) ant; return res; end nbsignataire ; end; 4) create or replace type body CPTCOURANT_TYPE as member function esttitulaire (x number) return bool is res bool; begin select count(*) into res from CPTCOURANT cpt where cpt.REF_CLIENT.num=x; if res==1 then return TRUE; else return FALSE; end if; end esttitulaire; end; 5) alter type CLIENT_TYPE add member procedure supprimeTel cascade; // 6) alter type CLIENT_TYPE add member procedure change_PortableTel cascade; create or replace type body CLIENT_TYPE as member procedure change_PortableTel (x IN NUMBER , y IN VARCHAR2(20))is Declare nouvtel TELEPHONE_VRY_TYPE; tel telephone_elt_vry_type; Begin select c.telephone_vry into nouvtel from client c where c.num =x; tel=telephone_elt_vry_type(y); nouvtel(3)=tel; update CLIENT c set c.telephone_vry=nouvtel where c.num=x; end change_PortableTel; end; //*******************/ execute change_PortableTel (1,'23123123'); 7) create view clientview(select c.nom,c.num from client c); 8) delete client c where c.num=10987

Das könnte Ihnen auch gefallen