*******************
******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;