0% found this document useful (0 votes)
41 views3 pages

Seance 3

The document discusses several PL/SQL exercises involving cursors and updating employee data. The exercises select employee data from tables and use cursors to loop through results, updating type of salary field based on salary amount. Output is formatted and printed.

Uploaded by

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

Seance 3

The document discusses several PL/SQL exercises involving cursors and updating employee data. The exercises select employee data from tables and use cursors to loop through results, updating type of salary field based on salary amount. Output is formatted and printed.

Uploaded by

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

*******************

******SEANCE 3*****
*******************

/*/*/*/* ExERCICE 1: */*/*/*/*/

////premiere methode://///

set serveroutput on;


declare
cursor c1 is
select ename,dname,sal,comm
from emp,dept
where emp.deptno=dept.deptno;
ligne_c1 c1%rowtype;

begin
open c1;
loop
fetch c1 into ligne_c1;
exit when c1%notfound;
if ligne_c1.comm is null then
dbms_output.put_line(rpad(ligne_c1.ename,15)||rpad(ligne_c1.dname,15)||
rpad(ligne_c1.sal,15)||'pas de commission');
else
dbms_output.put_line(rpad(ligne_c1.ename,15)||rpad(ligne_c1.dname,15)||
rpad(ligne_c1.sal,15)||rpad(ligne_c1.comm,4));
end if;
end loop;
close c1;
end;

////deuxieme methode://///

set serveroutput on;


declare
cursor c1 is
select ename,dname,sal,comm
from emp,dept
where emp.deptno=dept.deptno;
ligne_c1 c1%rowtype;
v_comm varchar2(20);

begin
open c1;
loop
fetch c1 into ligne_c1;
exit when c1%notfound;
if ligne_c1.comm is null then
v_comm:='pas de commision';
else
v_comm:=ligne_c1.comm;
end if;
dbms_output.put_line(rpad(ligne_c1.ename,15)||rpad(ligne_c1.dname,15)||
rpad(ligne_c1.sal,15)||rpad(v_comm,30));
end loop;
close c1;
end;

/*/*/*/* ExERCICE 1: */*/*/*/*/

set serveroutput on;


declare
cursor c1 is
select ename,dname,sal,comm
from emp,dept
where emp.deptno=dept.deptno for update of typeSal;
ligne_c1 c1%rowtype;
v_typeSal varchar2(50);
begin
open c1;
loop
fetch c1 into ligne_c1;
exit when c1%notfound;
if ligne_c1.sal<2000 then
v_typeSal:='salaire moyen';
elsif ligne_c1.sal>=2000 and ligne_c1.sal<=4000 then
v_typeSal:='bon salaire';
elsif ligne_c1.sal>=4000 then
v_typeSal:='tr�s bon salaire';
end if;
update emp
set typeSal =v_typeSal
where current of c1;
dbms_output.put_line(rpad(ligne_c1.ename,15)||rpad(ligne_c1.dname,15)||
rpad(ligne_c1.sal,15)||rpad(ligne_c1.sal,15)||v_typeSal);
end loop;
close c1;
end;

/*/*/*/* ExERCICE 2: */*/*/*/*/


set serveroutput on;
declare
cursor c1 is
select ename,dname,sal,comm
from emp,dept
where emp.deptno=dept.deptno for update of typeSal;
ligne_c1 c1%rowtype;
v_typeSal varchar2(50);
begin
open c1;
loop
fetch c1 into ligne_c1;
exit when c1%notfound;
if ligne_c1.sal<2000 then
v_typeSal:='salaire moyen';
elsif ligne_c1.sal>=2000 and ligne_c1.sal<=4000 then
v_typeSal:='bon salaire';
elsif ligne_c1.sal>=4000 then
v_typeSal:='tr�s bon salaire';
end if;
update emp
set typeSal =v_typeSal
where current of c1;
dbms_output.put_line(rpad(ligne_c1.ename,15)||rpad(ligne_c1.dname,15)||
rpad(ligne_c1.sal,15)||rpad(ligne_c1.sal,15)||rpad(ligne_c1.typeSal,15));
end loop;
close c1;
end;

You might also like