Вы находитесь на странице: 1из 11

Crearea bazei de date in ORACLE

CREATE TABLE comisioane (


id_comision VARCHAR2(4) NOT NULL,
den_comision VARCHAR2(30),
valoare NUMBER(3, 0),
CONSTRAINT pk_id_comision PRIMARY KEY (id_comision)
);
CREATE TABLE "comisioane tipuri_credite"(
id_comision VARCHAR2(4) NOT NULL,
tip_credit VARCHAR2(4) NOT NULL,
CONSTRAINT PK25 PRIMARY KEY (id_comision, tip_credit)
);
CREATE TABLE "comisioane tipuri_depozite" (
id_comision VARCHAR2(4) NOT NULL,
tip_depozit VARCHAR2(3) NOT NULL,
CONSTRAINT PK28 PRIMARY KEY (id_comision, tip_depozit)
);
CREATE TABLE conturi (
nrcontiban CHAR(24) NOT NULL
CONSTRAINT ck_nrcontiban CHECK (nrcontiban=ltrim(upper(nrcontiban))),
codfiscal VARCHAR2(9),
sold NUMBER(9, 0),
CONSTRAINT pk_nrcontiban PRIMARY KEY (nrcontiban)
);
CREATE TABLE credite (
id_credit VARCHAR2(5) NOT NULL,
nrcontiban CHAR(24),
suma_credit NUMBER(9, 0),
perioada NUMBER(3, 0),
rata NUMBER(9, 0),
tip_credit VARCHAR2(4),
CONSTRAINT pk_credite1 PRIMARY KEY (id_credit)
);
CREATE TABLE depozite (
id_depozit VARCHAR2(5) NOT NULL,
tip_depozit VARCHAR2(3),
nrcontiban CHAR(24),
suma_depozit NUMBER(9, 0),
data_depozit DATE DEFAULT sysdate,
CONSTRAINT pk_id_depozit PRIMARY KEY (id_depozit)
);
CREATE TABLE documente (
tip_doc VARCHAR2(3) NOT NULL,
den_doc VARCHAR2(20),
CONSTRAINT pk_tip_doc PRIMARY KEY (tip_doc)
);

1
CREATE TABLE parteneri (
nrcontpartener CHAR(24) NOT NULL,
codfiscpartener CHAR(9),
banca VARCHAR2(20)
CONSTRAINT ck_banca CHECK (banca=ltrim(upper(banca))),
numepartener VARCHAR2(15)
CONSTRAINT ck_numepartener CHECK (numepartener=ltrim(upper(numepartener))),
CONSTRAINT pk_nrcontpartener PRIMARY KEY (nrcontpartener)
);
CREATE TABLE plata_depozit (
id_plata_depozit CHAR(10) NOT NULL,
suma_platita NUMBER(10, 2),
data_plata DATE,
tip_tranzactie VARCHAR2(4),
id_depozit VARCHAR2(5) NOT NULL,
CONSTRAINT PK21 PRIMARY KEY (id_plata_depozit)
);
CREATE TABLE plata_furnizor (
id_plata_furnizor NUMBER(5, 0) NOT NULL,
nrcont CHAR(24),
nrcontpartener CHAR(24),
suma_platita NUMBER(9, 0),
data_plata DATE DEFAULT sysdate,
tip_tranzactie VARCHAR2(4),
CONSTRAINT pk_plata_furnizor PRIMARY KEY (id_plata_furnizor)
);

CREATE TABLE plata_rata (


id_plata_rata NUMBER(5, 0) NOT NULL,
id_credit VARCHAR2(5),
suma_platita NUMBER(9, 0),
data_plata DATE DEFAULT sysdate,
tip_tranzactie VARCHAR2(4),
CONSTRAINT pk_plata_rata PRIMARY KEY (id_plata_rata)
);
CREATE TABLE reprezentanti_banca (
cnp_reprez VARCHAR2(14) NOT NULL,
nume_reprez VARCHAR2(20)
CONSTRAINT ck_nume_reprez CHECK (nume_reprez=LTRIM(INITCAP(nume_reprez))),
CONSTRAINT nn_cnp_reprez PRIMARY KEY (cnp_reprez)
);
CREATE TABLE societati (
codfiscal VARCHAR2(9) NOT NULL
CONSTRAINT ck_codfiscal CHECK (SUBSTR(codfiscal,1,1) =
UPPER(SUBSTR(codfiscal,1,1))),
cnp_rep NUMBER(13, 0),
reprezentant VARCHAR2(30),
den_soc VARCHAR2(30)
CONSTRAINT ck_den_soc CHECK (den_soc=LTRIM(INITCAP(den_soc))),

2
adresa VARCHAR2(40)
CONSTRAINT ck_adresa CHECK (SUBSTR(adresa,1,1) = UPPER(SUBSTR(adresa,1,1))),
nrrc VARCHAR2(13),
tel VARCHAR2(10),
forma_jur VARCHAR2(5),
capital NUMBER(10, 0),
CONSTRAINT pk_codfiscal PRIMARY KEY (codfiscal)
);
CREATE TABLE tip_tranzactii (
tip_tranzactie VARCHAR2(4) NOT NULL,
den_tranzactie VARCHAR2(30),
tip_doc VARCHAR2(3),
cnp_reprez VARCHAR2(14),
CONSTRAINT pk_id_tranzactii PRIMARY KEY (tip_tranzactie)
);

CREATE TABLE tipuri_credite (


tip_credit VARCHAR2(4) NOT NULL,
den_credit VARCHAR2(40)
CONSTRAINT ck_den_credit CHECK (den_credit=ltrim(upper(den_credit))),
dobanda NUMBER(4, 2),
sumamin NUMBER(9, 0),
sumamax NUMBER(9, 0),
valuta CHAR(3) NOT NULL
CONSTRAINT ck_valuta_credite CHECK (valuta in ('RON','EUR','USD')),
perioada_max NUMBER(3, 0),
CONSTRAINT pk_tipuri_credite PRIMARY KEY (tip_credit) );

CREATE TABLE tipuri_depozite (


tip_depozit VARCHAR2(3) NOT NULL
CONSTRAINT ck_tip_depozit CHECK (tip_depozit=ltrim(upper(tip_depozit))),
dobanda NUMBER(4, 2),
sumamin NUMBER(9, 0),
den_depozit VARCHAR2(40)
CONSTRAINT ck_den_depozit CHECK (den_depozit=ltrim(upper(den_depozit))),
valuta CHAR(3) NOT NULL
CONSTRAINT ck_valuta CHECK (valuta in ('RON','EUR','USD')),
nr_luni NUMBER(3, 0),
CONSTRAINT pk_tip_depozit PRIMARY KEY (tip_depozit)
);
Alte obiecte din baza de date
-- View care sa includa numai societati cu adresa in Iasi
CREATE VIEW Soc_Iasi_view AS
SELECT * FROM societati
WHERE adresa like '%Iasi%';
- Secventa - poate fi folosita pentru generare valori unice pt cheia primara (din tabela Credite de
exemplu)
CREATE SEQUENCE seq_credit start with 100 Increment by 10 Maxvalue 1000 nocycle;

3
Inserarea de date in tabelele bazei de date:
---insert into societati
insert into societati values ('R1570298','2780221350102','Stroescu Mihaela','Otiolida','Str. Calarasi,nr
3,iasi','J40/6202/1991','0232302411','SA',2500);
insert into societati values ('R1242536','1580930378954','Mihaila Eugen','Francuta','Str. libertatii, nr
32,pascani,jud iasi','J53/2541/2000','0232455198','SRL',1000);
insert into societati values ('R2148791','2480131456789','Murariu Narcisa','Romcasa','Str. pacurari,nr
121,iasi','J21/1001/1998','0232455788','SA',65000);
insert into societati values ('R1054605','1650524214598','Ionescu Mihai','Doratex','Str. carol,nr 432,
botosani','J65/8493/2001','0231478988','SRL',54630);
insert into societati values ('R4377784','2681014256487','Dumitriu Ionela','Recor','Str. gen teleman,nr
1,husi,jud vaslui','J23/3200/1997', '0235481107','SA',2600);

--insert into reprezenti banca


insert into reprezentanti_banca values ('2780221350102','Stroescu Mihaela');
insert into reprezentanti_banca values ('1580930378954','Mihaila Eugen');
insert into reprezentanti_banca values ('2480131456789','Murariu Narcisa');
insert into reprezentanti_banca values ('1650524214598','Ionescu Mihai');
insert into reprezentanti_banca values ('2681014256487','Dumitriu Ionela');
insert into reprezentanti_banca values ('1710808124569','Lupascu Viorel');

--insert into documente


insert into documente values ('CEC','Cec');
insert into documente values ('FV','Foaie de varsamant');
insert into documente values ('BO','Bilet la ordin');
insert into documente values ('OP','Ordin de plata');

--insert into conturi


insert into conturi values ('RO23BRDE220SV03805172200','R1570298',2000);
insert into conturi values ('RO25BRDE102SV03452162400','R1242536',1500);
insert into conturi values ('RO32BRDE146SV14568924001','R2148791',3000);
insert into conturi values ('RO25BRDE231SV01246662400','R1054605',25630);
insert into conturi values ('RO25BRDE231SV01246662411','R1054605',25630);
insert into conturi values ('RO25BRDE231SV01246662422','R1054605',25630);
insert into conturi values ('RO04BRDE123LC24568230012','R4377784',45300);

4
--insert into parteneri
insert into parteneri values ('RO12RBCN124SV126487249XX','R15498630','BCR','HELIORET');
insert into parteneri values ('RO12RBCN1241212648724XXX','R15494234','BCR','INTERTRANS');
insert into parteneri values
('RO12BTRL12412126414678XX','R15493021','TRANSILVANIA','RECON');
insert into parteneri values
('RO12BTRL12124536488724XX','R15214041','TRANSILVANIA','ECOSIF');
insert into parteneri values ('RO51BRMA0730073850330000','R15126432','BANCA
ROMANEASCA','OPTINERG');
insert into parteneri values ('RO39BRMA0730073850395400','R84500314','BANCA
ROMANEASCA','CONDIOS');
insert into parteneri values ('RO04BRMA0730073850300000','R24361001','BANCA
ROMANEASCA','VALICO');
insert into parteneri values ('RO34BPOS70001038788USD02','R23164870','BANCPOST','ANAEC');
insert into parteneri values ('RO17BPOS70003038788EUR01','R12030141','BANCPOST','SELGROS');
insert into parteneri values ('RO12BPOS70003038788ROL06','R24301610','BANCPOST','ROMCARD');
insert into parteneri values ('RO82BPOS70003038788ROL07','R21304121','BANCPOST','DILODOL');

--insert into tipuri_depozite


insert into tipuri_depozite values ('VD',0.25,0,'LA VEDERE','RON',0);
insert into tipuri_depozite values ('T1',5.50,2500,'LA TERMEN DE 1 LUNA','RON',1);
insert into tipuri_depozite values ('T3',5.75,2500,'LA TERMEN DE 3 LUNI','RON',3);
insert into tipuri_depozite values ('T6',6.00,2500,'LA TERMEN DE 6 LUNI','RON',6);
insert into tipuri_depozite values ('T9',6.25,2500,'LA TERMEN DE 9 LUNI','RON',9);
insert into tipuri_depozite values ('T12',6.50,2500,'LA TERMEN DE 12 LUNI','RON',12);
insert into tipuri_depozite values ('T18',7.00,2500,'LA TERMEN DE 18 LUNI','RON',18);
insert into tipuri_depozite values ('OVN',3.50,3000,'DEPOZIT OVERNIGHT','RON',0);
insert into tipuri_depozite values ('E1',2.50,0,'DEPOZIT LA TERMEN DE 1 LUNA IN EURO','EUR',1);
insert into tipuri_depozite values ('E3',3.00,0,'DEPOZIT LA TERMEN DE 3 LUNI IN EURO','EUR',3);
insert into tipuri_depozite values ('E6',3.10,0,'DEPOZIT LA TERMEN DE 6 LUNI IN EURO','EUR',6);
insert into tipuri_depozite values ('E9',3.25,0,'DEPOZIT LA TERMEN DE 9 LUNI IN EURO','EUR',9);
insert into tipuri_depozite values ('E12',3.50,0,'DEPOZIT LA TERMEN DE 12 LUNI IN
EURO','EUR',12);
insert into tipuri_depozite values ('E18',4.00,0,'DEPOZIT LA TERMEN DE 18 LUNI IN
EURO','EUR',18);
insert into tipuri_depozite values ('D1',2.75,0,'DEPOZIT LA TERMEN DE 1 LUNA IN USD','USD',1);
insert into tipuri_depozite values ('D3',3.25,0,'DEPOZIT LA TERMEN DE 3 LUNI IN USD','USD',3);

5
insert into tipuri_depozite values ('D6',3.50,0,'DEPOZIT LA TERMEN DE 6 LUNI IN USD','USD',6);
insert into tipuri_depozite values ('D9',3.75,0,'DEPOZIT LA TERMEN DE 9 LUNI IN USD','USD',9);
insert into tipuri_depozite values ('D12',4.00,0,'DEPOZIT LA TERMEN DE 12 LUNI IN
USD','USD',12);
insert into tipuri_depozite values ('D18',4.25,0,'DEPOZIT LA TERMEN DE 18 LUNI IN
USD','USD',18);

--insert into tipuri_credit


insert into tipuri_credite values ('C1','CREDIT PENTRU NEVOI
TEMPORARE',0.25,1500,80000,'RON',2);
insert into tipuri_credite values ('C2','CREDIT PENTRU CAPITAL DE
LUCRU',0.12,20000,150000,'RON',12);
insert into tipuri_credite values ('C3','CREDIT PENTRU INVESTITII',0.11,5000,1000000,'EUR',60);
insert into tipuri_credite values ('C4','CREDIT START-UP',0.12,1000,85000,'RON',60);
insert into tipuri_credite values ('C5','CREDIT PENTRU NEVOI
DIVERSE',0.16,1000,200000,'EUR',240);
insert into tipuri_credite values ('C6','CREDIT MICRO PT IMM-URI',0.15,2000,50000,'EUR',12);

--insert into comisioane


insert into comisioane values ('DES','Comision de deschidere',0.25);
insert into comisioane values ('RET','Comision de retragere',0.40);
insert into comisioane values ('ADM','Comision de administrare',7);
insert into comisioane values ('VIR','Comision de virament',20);
insert into comisioane values ('FC','Fara comision',0);

--insert into depozite


insert into depozite values
(1,'T6','RO32BRDE146SV14568924001',5000,TO_DATE('15/09/2006','DD/MM/YYYY'));
insert into depozite values
(2,'T12','RO04BRDE123LC24568230012',7500,TO_DATE('16/10/2006','DD/MM/YYYY'));
insert into depozite values
(3,'OVN','RO32BRDE146SV14568924001',80000,TO_DATE('04/12/2006','DD/MM/YYYY'));
insert into depozite values
(4,'E6','RO32BRDE146SV14568924001',5000,TO_DATE('11/06/2006','DD/MM/YYYY'));
insert into depozite values
(5,'T6','RO23BRDE220SV03805172200',10000,TO_DATE('23/11/2006','DD/MM/YYYY'));
insert into depozite values
(6,'E12','RO32BRDE146SV14568924001',4500,TO_DATE('13/05/2006','DD/MM/YYYY'));

6
--insert into credite
INSERT INTO CREDITE VALUES '10','RO23BRDE220SV03805172200',50000,6,null,'C2');
INSERT INTO CREDITE VALUES ('11','RO04BRDE123LC24568230012',25000,36,null,'C3');
INSERT INTO CREDITE VALUES ('12','RO04BRDE123LC24568230012',5000,240,null,'C5');
INSERT INTO CREDITE VALUES ('14','RO25BRDE102SV03452162400',10000,1,null,'C1');
INSERT INTO CREDITE VALUES ('16','RO04BRDE123LC24568230012',50000,120,null,'C5');
INSERT INTO CREDITE VALUES ('18','RO25BRDE102SV03452162400',75000,2,null,'C1');
INSERT INTO CREDITE VALUES ('20','RO23BRDE220SV03805172200',900000,36,null,'C3');

--insert into tip tranzactii


insert into tip_tranzactii values ('PR','plata rata','OP',2780221350102);
insert into tip_tranzactii values ('PF','plata furnizor','BO',1580930378954 );
insert into tip_tranzactii values ('INC','incasari','CEC',2480131456789);
insert into tip_tranzactii values ('ICR','incasare_credit','FV',1650524214598 );
insert into tip_tranzactii values ('CD','calcul dobanda','FV',2681014256487);
insert into tip_tranzactii values ('CC','calcul comision','FV',1710808124569);
insert into tip_tranzactii values ('CCC','calcul comision credit','FV',1710808124569);
insert into tip_tranzactii values ('CDC','calcul dobanda credit','FV',2480131456789);

--insert into plata_rata


insert into plata_rata values (100,'10',2003,TO_DATE('15/09/2006','DD/MM/YYYY'),'PR');
insert into plata_rata values (101,'11',102,TO_DATE('14/03/2006','DD/MM/YYYY'),'PR');
insert into plata_rata values (102,'12',120,TO_DATE('14/03/2007','DD/MM/YYYY'),'PR');
insert into plata_rata values (103,'20',1500,TO_DATE('02/03/2007','DD/MM/YYYY'),'PR');
insert into plata_rata values (104,'11',300,TO_DATE('10/05/2007','DD/MM/YYYY'),'PR');
insert into plata_rata values (105,'14',580,TO_DATE('09/11/2006','DD/MM/YYYY'),'PR');
insert into plata_rata values (106,'16',8623,TO_DATE('05/01/2007','DD/MM/YYYY'),'PR');
insert into plata_rata values (107,'18',2130,TO_DATE('24/12/2006','DD/MM/YYYY'),'PR');
-- insert into plata_furnizor
insert into plata_furnizor values
('201','RO25BRDE102SV03452162400','RO12BPOS70003038788ROL06',1500,TO_DATE('24/12/2006'
,'DD/MM/YYYY'),'PF');
insert into plata_furnizor values
('202','RO04BRDE123LC24568230012','RO17BPOS70003038788EUR01',200,TO_DATE('15/11/2006','
DD/MM/YYYY'),'PF');
insert into plata_furnizor values

7
('203','RO32BRDE146SV14568924001','RO04BRMA0730073850300000',150,TO_DATE('24/02/2007','
DD/MM/YYYY'),'PF');
insert into plata_furnizor values
('204','RO04BRDE123LC24568230012','RO82BPOS70003038788ROL07',320,TO_DATE('02/06/2007','
DD/MM/YYYY'),'PF');
insert into plata_furnizor values
('205','RO23BRDE220SV03805172200','RO12BTRL12412126414678XX',100,TO_DATE('31/12/2006','
DD/MM/YYYY'),'PF');
insert into plata_furnizor values
('207','RO25BRDE102SV03452162400','RO12RBCN1241212648724XXX',231,TO_DATE('24/03/2007'
,'DD/MM/YYYY'),'PF');
insert into plata_furnizor values
('208','RO04BRDE123LC24568230012','RO12BPOS70003038788ROL06',5000,TO_DATE('14/05/2007'
,'DD/MM/YYYY'),'PF');
--insert into plata_depozit
insert into plata_depozit values
('301', 5000,TO_DATE('24/12/2006','DD/MM/YYYY'),'PR',1);
insert into plata_depozit values
('302', 200,TO_DATE('24/01/2007','DD/MM/YYYY'),'PR',1);
insert into plata_depozit values
('303',260,TO_DATE('28/02/2008','DD/MM/YYYY'),'PR',2);
insert into plata_depozit values
('304', 99000,TO_DATE('14/12/2009','DD/MM/YYYY'),'PR',3);
insert into plata_depozit values
('305', 700,TO_DATE('15/04/2008','DD/MM/YYYY'),'PR',4);
insert into plata_depozit values
('306', 52500,TO_DATE('24/12/2009','DD/MM/YYYY'),'PR',4);
insert into plata_depozit values
('307', 8900,TO_DATE('07/12/2006','DD/MM/YYYY'),'PR',5);
--insert into "comisioane tipuri_credite"
insert into "comisioane tipuri_credite" values ('DES', 'C1');
insert into "comisioane tipuri_credite" values ('DES', 'C2');
insert into "comisioane tipuri_credite" values ('DES', 'C3');
insert into "comisioane tipuri_credite" values ('DES', 'C4');
insert into "comisioane tipuri_credite" values ('FC', 'C5');
insert into "comisioane tipuri_credite" values ('FC', 'C6');

8
--insert into "comisioane tipuri_depozite"
insert into "comisioane tipuri_depozite" values('DES', 'VD');
insert into "comisioane tipuri_depozite" values('DES', 'D9');
insert into "comisioane tipuri_depozite" values('FC', 'VD');
insert into "comisioane tipuri_depozite" values('FC', 'D6');

Interogarea bazei de date


Adaugati coloana Cifra_afaceri in tabela Societati, de tip numeric(10)
ALTER TABLE societati
ADD (cifra_afaceri number(10));
Modificaţi în Stroescu Mirela numele reprezentantului societatii care are nr de telefon 0232302411:
UPDATE societati
SET reprezentant='Stroescu Mirela'
WHERE codfiscal=( select codfiscal
from societati
where tel= '0232302411');
In tabela tipuri_credite modificati valoarea dobanzii pentru tipul de credit „CREDIT PENTRU
INVESTITII” cu 5 %
UPDATE tipuri_credite
SET dobanda=dobanda*1.05
WHERE den_credit='CREDIT PENTRU INVESTITII';

Stergeti inregistrarea din tabela depozite pentru depozitul cu data 04-12-2006


DELETE FROM tipuri_depozite
WHERE den_depozit='DEPOZIT LA TERMEN DE 1 LUNA IN EURO';
Care sunt depozitele care contin comision de deschidere?
select den_depozit
from tipuri_depozite t inner join "comisioane tipuri_depozite" cd
on t.tip_depozit= cd.tip_depozit
inner join comisioane c
on cd.id_comision= c.id_comision
where c.id_comision='DES';
Care sunt creditele pentru care nu se percepe comision ?
select den_credit
from tipuri_credite t inner join "comisioane tipuri_credite" cc
on t.tip_credit= cc.tip_credit
inner join comisioane c
on cc.id_comision= c.id_comision
where c.id_comision='FC';
Sa se afiseze tipul documentelor care au loc in tranzactiile facute de angajata ‚Mihaela Stroescu’
select den_doc
from documente d , tip_tranzactii tt
where d.tip_doc= tt.tip_doc

9
and tt.tip_tranzactie= (select tip_tranzactie
from reprezentanti_banca rb inner join tip_tranzactii tt
on rb.cnp_reprez=tt.cnp_reprez
where nume_reprez='Stroescu Mihaela');

Sa se specifice numarul de tranzactii realizate de fiecare reprezentant al bancii


select cnp_reprez, count(den_tranzactie)
from tip_tranzactii
group by cnp_reprez, tip_tranzactie;
Sa se specifice denumirea societatii, capitalul social si suma credita pentru societatile care au credite intre
25000 si 50000
select den_soc Denumire_societate, s.capital Capital_social, suma_credit
from societati s inner join conturi c
on s.codfiscal= c.codfiscal
inner join credite cr
on c.nrcontiban=cr.nrcontiban
where suma_credit BETWEEN 25000 and 50000;
Care este creditul cu cea mai mare dobanda
select den_credit
from tipuri_credite
where dobanda=( select max(dobanda)
from tipuri_credite);
Care este creditul cel mai avantajos
select den_credit
from tipuri_credite
where dobanda=( select min(dobanda)
from tipuri_credite);
Care este cel mai avantajos depozit
select den_credit
from tipuri_credite
where dobanda=( select min(dobanda)
from tipuri_credite);
Suma totala a depozitelor pentru anul 2015
select sum( suma_depozit) suma_totala_2015
from tipuri_depozite tp inner join depozite d
on tp.tip_depozit=d.tip_depozit
where data_depozit like '%06%';
Suma medie depusa in anul 2015
select round(avg( suma_depozit)) suma_totala_2015
from tipuri_depozite tp inner join depozite d
on tp.tip_depozit=d.tip_depozit
where data_depozit like '%15%';
Suma totala pentru fiecare tip de credit
select tip_credit ,sum(suma_credit ) suma_imprumutata
from credite
group by tip_credit;

10
Sa se afiseze numele partenerilor care au conturi deschise la BCR si cei al caror cont incepe cu 'RO82%'
select numepartener
from parteneri
where banca='BCR'
union
select numepartener
from parteneri
where codfiscpartener like 'RO82%';

Sa se afiseze societatile care au aceeasi forma juridica ca si clientul R2148791


select den_soc
from societati
where forma_jur=( select forma_jur
from societati
where codfiscal=R2148791);

11

Оценить