Update Emp Set Sal Sal+sal 0.15 Where Empno &empno If Sql%found Then Dbms - Output - Put - Line ( Employee Record Modified')
Update Emp Set Sal Sal+sal 0.15 Where Empno &empno If Sql%found Then Dbms - Output - Put - Line ( Employee Record Modified')
BEGIN
if sql%found then
else
end if;
END;
BEGIN
where empno=&empno;
if sql%notfound then
else
end if;
end;
/
3 –IMPLICIT CURSOR : USE OF %ROWCOUNT ATTRIBUTE
/* WAB which accepts deptno from user and updates salary of all the employees of that department by 15%.
Display the message how many records are updated at the end. */
DECLARE
no number(2);
BEGIN
no :=sql%rowcount;
else
end if;
END;
EXPLICIT CURSORS
4 /* Display empno, salary end empname of all the emps from emp table.*/
declare
cursor c_emp is
eno emp.empno%type;
sal emp.sal%type;
enm emp.ename%type;
begin
open c_emp;
if c_emp%isopen then
loop
end loop;
commit;
close c_emp;
else
end if;
end;
5 /* WAB which accept the deptno from user and display eno, salary, empname of all the employees
working in that deptno. */
declare
cursor c_emp is
eno emp.empno%type;
sal emp.sal%type;
enm emp.ename%type;
begin
open c_emp;
if c_emp%isopen then
loop
end loop;
commit;
close c_emp;
else
end if;
end;
6 /* WAB which accept department no from user and increment the salary of all the employees working in
that dept by 5%. */
— Use of %NOTFOUND
declare
cursor c_emp is
eno emp.empno%type;
sal emp.sal%type;
begin
open c_emp;
if c_emp%isopen then
loop
end loop;
commit;
close c_emp;
else
end if;
end;
7 /* WAB which accept department no from user and increment the salary of all the employees working in
that dept by 5%. */
— Use of %FOUND
declare
eno emp.empno%type;
sal emp.sal%type;
begin
open c_emp;
loop
if c_emp%found then
commit;
else
exit;
end if;
end loop;
close c_emp;
end;
eno emp.empno%type;
nm emp.empname%type;
sal emp.sal%type;
begin
open c_emp;
loop
fetch c_emp into eno,nm,sal;
end loop;
close c_emp;
end;
9 /* WAB which accept the deptno from user and display eno, salary, empname of all the employees
working in that deptno. */
— Demo of cursor for loop.
declare
cursor c_emp is
begin
for c in c_emp
loop
end loop;
end;
/* WAB which inserts all the students living in Rajkot from table emp into table stud_Rajkot. */
DECLARE
FOR x IN c_student
LOOP
END LOOP;
END;
cursor c_emp is
begin
for c in c_emp
loop
end loop;
commit;
end;
11 — Write a block using cursor which display the sum of salary department wise.
declare
–rec c1%rowtype;
sal emp.sal%type;
begin
for rec in c1
loop
dbms_output.put_line(‘ ‘);
end loop;
end;
12 /* WAB which accept city from user and display empno and name employees living in that city. */
declare
rec c1%rowtype;
tcity emp.city%type;
begin
tcity:=’&city’;
loop
dbms_output.put_line(‘ ‘);
end loop;
end;
13 /* Use of parameterized cursor. Write a PL/SQL block which check for the existence
of deptno. if exist then enter the record for employee into emp table.*/
declare
d_no number(4);
eno number(5);
nm varchar2(15);
begin
eno :=&empno;
nm:=’&empname’;
d_no:=&deptno;
open c2(d_no);
if c2%found then
else
end if;
close c2;
end;
cursor c2(xdeptno number) is select sum(sal) from emp group by deptno having deptno=xdeptno;
dno number;
sal emp.sal%type;
begin
for i in c1 loop
–dno:=c1.deptno;
dbms_output.put_line(i.deptno||’: ‘||i.dname);
dno:=i.deptno;
open c2(dno);
close c2;
end loop;
end;