DBMS Week10
DBMS Week10
WEEK-10
Name: Class:CSM-C
Rollno: Date:21/06/24
Opening cursors:
Syntax:
Open cursor_name;
Program:
Open cursor1;
Fetching the data:
Syntax:
fetch cursor_name into declared variables;
Program:
Fetch cursor1 into id,name,marks;
exit when s1%notfound;
Closing cursor:
Syntax:
Close cursor_name;
Program:
Close cursor1;
Implict cursor:
Program:
create table employee(e_id number(10),e_name varchar(20),e_salary number(10))
insert into employee values(1,'ALPHA',20000)
insert into employee values(2,'BETA',30000)
insert into employee values(3,'GAMMA',40000)
insert into employee values(4,'THETHA',20000)
Begin
For A in (Select e_id, e_name, e_salary from employee) loop
Dbms_output.put_line(A.e_id || ' ' || A.e_name || ' ' || A.e_salary);
End loop;
End
Output:
Explict cursor:
Program:
create table student(s_id number(10),s_name varchar(20),s_marks number(10))
drop table student
insert into student values(1,'XYZ',90)
insert into student values(2,'PQR',90)
insert into student values(3,'ABC',90)
insert into student values(4,'JUNNU',90)
select * from student
declare
id number;
name varchar(10);
marks number;
cursor cursor1 is
select s_id,s_name,s_marks from student;
begin
open cursor1;
loop
fetch cursor1 into id,name,marks;
exit when cursor1%notfound;
dbms_output.put_line(id||' '||name||' '||marks);
end loop;
close cursor1;
end;
Output:
OUTPUT: