CREATE TABLE banque
(
code_banque VARCHAR(10),
r_social VARCHAR(10),
capital DOUBLE (5,3),
adresse VARCHAR (10),
CONSTRAINT pk_banque PRIMARY KEY (code_banque)
);
CREATE TABLE agence
code_agence VARCHAR(10),
libelle VARCHAR(10),
adresse VARCHAR (10),
latitude VARCHAR (10),
longtitude VARCHAR (10),
CONSTRAINT pk_agence PRIMARY KEY (code_agence),
CONSTRAINT fk_agence FOREIGN KEY (code_banque) REFERENCES banque(code_banque));
);
CREATE TABLE client
code_client VARCHAR(10),
nom VARCHAR(10),
adresse VARCHAR (10),
téléphone VARCHAR (10),
CONSTRAINT pk_client PRIMARY KEY (code_client)
);
CREATE TABLE compte
num_compt VARCHAR(10),
solde DOUBLE (10,3),
sl_débit VARCHAR (10),
date_sld DATE ,
etat VARCHAR(10),
CONSTRAINT pk_compte PRIMARY KEY (num_compt),
CONSTRAINT fk_compte FOREIGN KEY (code_client) REFERENCES client(code_client));
);
CREATE TABLE carte
num_carte VARCHAR(16),
type_carte VARCHAR(10);
plafond DOUBLE (10,3),
date_exp DATE ,
CONSTRAINT pk_carte PRIMARY KEY (num_carte)
CONSTRAINT fk_carte FOREIGN KEY (num_compt) REFERENCES compte(num_compt));
);
FONCTION retrait(Vnum_compte.num_compte%type,montant_compte.solde%type)return
compte.solde%type
DECLARE
v_solde compte.solde%type;
cursor c1 is select nom seuil from compte where num_compte=num
c2 c1%Rowtype;
from c1 in c2 loop
if(c2.solde-montant>seuil)
v_solde=c2.solde-montant;
Endif;
Endloop;
update compte
set solde=v_solde
where num_compte=num;
return solde
exeption
when NO_FOUND_DATA then
raise_application_error(-20130"");
funtion versement (num compte.num_compte%type,montant compte.solde%type)return
compte.solde%type
begin
update compte
set solde=solde+montant
where num_compte=num;
return solde
exeption
when NO_DATA_FOUND then
raise_application_error(-20120"");
create or replace trigger c_compte after update on compte
for eatch row
if (;old.solde>:new.solde)and(etat="bloque")
raise_application_error(-20190"");
endif
end
function retrait carte(num carte.num_carte%type,montant compte.solde%type)return
compte.solde%type
declare
v_solde compte.solde%type
cursor c1 is select A.solde,B.plafound from A.compte,B carte where a.num_compte=b.num_compte
and a.num_catre=num;
c2 c1%rowtypes
v_sole compte.solde%type;
begin
from c1 in c1 loop
if c2.solde-montant>plafond then
v_solde=c1.solde-montant;
else
raise_application_error(-20133"");
endif;
end loop;
update compte
set compte.solde=v_solde
where compte num_compte=carte_num_compte and carte_num_carte=num;
exeption
when no_data_found then raise application_error(-20145"no found");
end;
create or replace procedure affichage IS
cursor c_list is select ag.CodeAgence, ag.Libelle,cl.Nom,Solde,MAX(com.solde) from Agence ag, Client
cl, Compte com
where (ag.CodeAgence = cl.CodeAgence) AND (cl.CodeClient = com.CodeClient);
c_variable c_list %rowtype
begin
open c_list;
fetch c_list into c_variable;
for c_variable in c_list loop
DBMS_OUTPUT.PUT_LINE (c_variable.libelle, c_variable.nom ,c_variable.solde);
end loop
end