Saturday, January 27, 2018

Pl/SQl Programs ADS

16.
declare
cursor cursor is select * from emp7567 order by salary desc;
id emp7567.id%type;
name emp7567.name%type;
salary emp7567.salary%type;
begin
open cursor;
loop
fetch cursor into id,name,salary;
dbms_output.put('Id: '||id||' ');
dbms_output.put('Name: '||name||' ');
dbms_output.put('Salary: '||salary||' ');
dbms_output.put_line(' ');
exit when(cursor%rowcount>5);
end loop;
close cursor;
end;

17.
declare
rows number;
begin

update emp7567
set
salary=salary+0.25*salary;

if sql%notfound then
dbms_output.put_line('No Row Updated');
else
rows:=sql%rowcount;
dbms_output.put_line(rows||' Rows Updated');
end if;


end;

18.

declare
cursor cursor is select * from emp7567;
id emp7567.id%type;
name emp7567.name%type;
salary emp7567.salary%type;
begin
open cursor;
loop
fetch cursor into id,name,salary;
dbms_output.put('Id: '||id||' ');
dbms_output.put('Name: '||name||' ');
dbms_output.put('Salary: '||salary||' ');
dbms_output.put_line(' ');
exit when(cursor%notfound);
end loop;
dbms_output.put_line(cursor%rowcount||' Results Found');
close cursor;
end;

19.

create trigger uppercase7567 before insert  or update on emp7567
for each row
when (New.id>0)
begin
:New.name:=UPPER(:new.name);
end;

20.