Sunteți pe pagina 1din 4

Laborator PL/SQL

Tranzactii-2

Intocmiţi un referat de laborator unde notaţi rezultatele problemelor propuse mai jos,
precum şi observaţiile si concluziile personale, ale dumneavoastră, la fiecare subiect.

Creaţi o tabelă T, cu două coloane numerice, A şi B.


Inseraţi trei rânduri, cu valorile (0,0), (2,3) et (0,1) şi confirmaţi tranzacţia.

Deschideţi două sesiuni ale aceluiaşi utilizator, care derulează fiecare câte o tranzacţie, T1 şi T2.
Urmăriţi derularea tranzacţiilor în situaţiile următoare (momentele de timp sunt dispuse cronologic
pe verticală, în jos); faceţi observaţii si trageţi concluzii:

1.
sesiunea 1 sesiunea 2
select * from T;
select * from T;
insert into T values (4,4);
select * from T;
insert into T values (5,5);
select * from T;
select * from T;
commit;
select * from T;
rollback;
select * from T;

2.
sesiunea 1 sesiunea 2
select * from T;
update T set A=A+1;
select * from T;
commit;
select * from T;
commit;

3.
sesiunea 1 sesiunea 2
select * from T;
update T set A=A+1;
select * from T;
insert into T values (3,7);
select * from T;
delete T where A=2;
delete T where A=1;
select * from T;
commit;
commit;
select * from T;
4.
sesiunea 1 sesiunea 2
select * from T;
update T set A=3 where A=2;
update T set B=2 where B=3;
select * from T;
select * from T;
update T set A=3 where A=2;
update T set B=2 where B=3;
commit;
commit;
select * from T;

5.
sesiunea 1 sesiunea 2
select * from T where B=7
for UPDATE;
update T set B=10 where B=0;
select * from T;
select * from T;
update T set A=5 where A=3;
update T set B=6 where B=7;
commit;
commit;
select * from T;

6.
sesiunea 1 sesiunea 2
set transaction read only;
select * from T;
select * from T;
update T set A=A+1;
commit;
select * from T;
select * from T;
update T set A=A+1;
commit;
select * from T;
commit;
select * from T;

7.
sesiunea 1 sesiunea 2
select * from T;
update T set A=A+1;
select * from T;
create table TT as (select * from T);
select * from T;
select * from TT;
select * from TT;
drop table TT;
rollback;
select * from TT;
Cum se comporta comenzile LDD in raport cu tranzactiile?

8.

Goliti tabela T.
Definiti o cheie primara
alter table T add constraint T_Pkey primary key(a);

Executati urmatoarele programe PL/SQL; consultati tabela T dupa fiecare exercitiu si trageti
concluzii.

a)
begin
insert into T values (-1,-1) ;
savepoint p1 ;
insert into T values (-2,-2) ;
rollback to p1 ;
commit ;
end ;

b)
create or replace procedure p(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
insert into T values (i1,i2+1);
insert into T values (i1+1,i2+1);
commit ;
end ;
execute p(50,50);
c)
create or replace procedure p(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
insert into T values (i1,i2+1);
insert into T values (i1+1,i2+1);
commit ;
exception
when others then dbms_output.put_line('pb insertion'); commit;
end ;
execute p(50,50);
d)
create or replace procedure pp(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
exception
when others then dbms_output.put_line('pb insertion'); commit;
end ;
create or replace procedure p(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
pp(i1,i2);
insert into T values (i1+1,i2+2);
commit ;
exception
when others then dbms_output.put_line('pb insertion'); commit;
end ;
execute p(60,60);
e)
create or replace procedure pp(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
insert into T values (i1+1,i2+1);
exception
when others then dbms_output.put_line('pb insertion pp');
end ;
create or replace procedure p(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
pp(i1+1,i2);
insert into T values (i1+1,i2+2);
commit ;
exception
when others then dbms_output.put_line('pb insertion p');
rollback;
end ;
execute p(70,70);
f)
create or replace procedure pp(i1 NUMBER, i2 NUMBER) is
begin
insert into T values (i1,i2);
insert into T values (i1+1,i2+1);
commit ;
exception
when others then dbms_output.put_line('pb insertion pp');
end ;
execute p(80,80);
g)
create or replace procedure pp(i1 NUMBER, i2 NUMBER) is
pragma autonomous_transaction ;
begin
insert into T values (i1,i2);
insert into T values (i1+1,i2+1);
commit ;
exception
when others then dbms_output.put_line('pb insertion pp');
end ;
execute p(90,90);