Assignment 5: 1.) Write A PL/SQL Code To Display A Message To Check Whether The Record Is Deleted or Not

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

ASSIGNMENT 5

1.) Write a PL/SQL code to display a message to check whether the record is deleted
or not.

create table cust(id NUMBER primary key,cname varchar(30),locality varchar(40));


insert into cust values(123,'rakesh','patiala');
declare
begin
delete from cust ;
if(SQL%FOUND) then
dbms_output.put_line('record is deleted ');
else
dbms_output.put_line('nothing deleted');
end if;
end;

2.) Write a PL/SQL code to display a message to provide the information about the
number of records deleted by the deleted statement issued in a PL/SQL block.

create table cust(id NUMBER primary key,cname varchar(30),locality varchar(40));


insert into cust values(123,'rakesh','patiala');
insert into cust values(124,'ram','chandigarh');
insert into cust values(125,'sachin','delhi');
declare
begin
delete from cust ;
if(SQL%FOUND) then
dbms_output.put_line('record is deleted ');
else
dbms_output.put_line('nothing deleted');
end if;
end;
3.) Write a PL/SQL code to display empno, ename, job of employee of department
number 10 for EMP table (empno, ename, job, sal, deptno).

create table emp(eno NUMBER primary key,ename varchar(30),job varchar(40),sal


NUMBER,deptno NUMBER);
insert into emp values(123,'rakesh','prof',50000,10);
insert into emp values(124,'anil','prof',60000,10);
insert into emp values(125,'arvind','T.A',30000,20);
insert into emp values(126,'sumit','asst. prof',70000,20);
insert into emp values(127,'vikram','asst. prof',70000,10);
declare
CURSOR cur IS Select eno,ename,job from emp where deptno=10;
rec cur%ROWTYPE;
begin
OPEN cur;
LOOP
FETCH cur INTO rec;
EXIT WHEN cur%NOTFOUND;
dbms_output.put_line('eno '||rec.eno||' ename '||rec.ename||' job '||rec.job);
END LOOP;
CLOSE cur;
end;

4.) Write a PL/SQL code to display the employee number and name of the top 5
highest paid employee.

create table emp(eno NUMBER primary key,ename varchar(30),job varchar(40),sal


NUMBER,deptno NUMBER);
insert into emp values(123,'rakesh','prof',50000,10);
insert into emp values(124,'anil','prof',60000,10);
insert into emp values(125,'arvind','T.A',30000,20);
insert into emp values(126,'sumit','asst. prof',70000,20);
insert into emp values(127,'vikram','asst. prof',70000,10);
insert into emp values(128,'vivek','prof',80000,10);
insert into emp values(129,'shyam','HOD',140000,20);
insert into emp values(130,'arjun','asst. prof',40000,20);
declare
CURSOR cur IS Select * from emp order by sal desc;
rec cur%ROWTYPE;
temp number:=1;
begin
OPEN cur;
LOOP
FETCH cur INTO rec;
EXIT WHEN cur%NOTFOUND or temp>5;
dbms_output.put_line('eno '||rec.eno||' ename '||rec.ename);
temp:=temp+1;
END LOOP;
CLOSE cur;
end;

5.) Write a PL/SQL code to display the empno, ename, job of employees of
department 10 using cursor for loop.

create table emp(eno NUMBER primary key,ename varchar(30),job varchar(40),sal


NUMBER,deptno NUMBER);
insert into emp values(123,'rakesh','prof',50000,10);
insert into emp values(124,'anil','prof',60000,10);
insert into emp values(125,'arvind','T.A',30000,20);
insert into emp values(126,'sumit','asst. prof',70000,20);
insert into emp values(127,'vikram','asst. prof',70000,10);
insert into emp values(128,'vivek','prof',80000,10);
insert into emp values(129,'shyam','HOD',140000,20);
insert into emp values(130,'arjun','asst. prof',40000,20);
declare
CURSOR cur IS Select * from emp where deptno=10;
begin
FOR rec IN cur LOOP
dbms_output.put_line('eno '||rec.eno||' ename '||rec.ename||' sal '||rec.sal);
END LOOP;
--CLOSE cur;
end;
6.) Write a PL/SQL code to display the employee number and name of the top 5
highest paid employee with CURSOR for loop statement.

create table emp(eno NUMBER primary key,ename varchar(30),job varchar(40),sal


NUMBER,deptno NUMBER);
insert into emp values(123,'rakesh','prof',50000,10);
insert into emp values(124,'anil','prof',60000,10);
insert into emp values(125,'arvind','T.A',30000,20);
insert into emp values(126,'sumit','asst. prof',70000,20);
insert into emp values(127,'vikram','asst. prof',70000,10);
insert into emp values(128,'vivek','prof',80000,10);
insert into emp values(129,'shyam','HOD',140000,20);
insert into emp values(130,'arjun','asst. prof',40000,20);
declare
CURSOR cur IS Select * from emp order by sal desc;
temp number:=1;
begin
FOR rec IN cur LOOP
EXIT WHEN temp>5;
dbms_output.put_line('eno '||rec.eno||' ename '||rec.ename);
temp:=temp+1;
END LOOP;

end;

You might also like