Sunday, 9 June 2013

PL/SQL program for explicit cursors

Creating a table:

Create table emp_29(e_no number, e_name varchar2(20),e_sal number)


Inserting values in the table:

Insert into emp3 (e_no,e_name,e_sal) values(1,'Mak',20000);
Insert into emp3 (e_no,e_name,e_sal) values(2,'Monish',25000);
Insert into emp3 (e_no,e_name,e_sal) values(3,'Murthy',25000);


PL/SQL block:

DECLARE
cursor emp_disp is
select e_name from emp3 ;
name1 emp3.e_name%type;
BEGIN
open emp_disp;
if emp_disp%ISOPEN then
    loop
    fetch emp_disp into name1;
    exit when emp_disp%NOTFOUND;
    if emp_disp%FOUND then
       dbms_output.put_line(name1);
    end if;
    end loop;
    commit;
else
     dbms_output.put_line('unable to open the cursor');
end if;
close emp_disp;
END;

No comments:

Post a Comment