Monday 24 June 2013

EXPLICIT CURSOR

Explicit Cursor : Syntax with Example

There are four steps in using an Explicit Cursor.

  • DECLARE the cursor in the declaration section.
  • OPEN the cursor in the Execution Section.
  • FETCH the data from cursor into PL/SQL variables or records in the Execution Section.
  • CLOSE the cursor in the Execution Section before you end the PL/SQL Block.
     

     Syntax:

     DECLARE
        variables;
        records;
        create a cursor;
     BEGIN 
       OPEN cursor;
       FETCH cursor;
         process the records;
       CLOSE cursor;
     END;
     
    Example: 
     
    declare
    abc tb1%rowtype;
    cursor c_cur is select * from tb1 where age>25;
    begin
    open c_cur;
    loop
    fetch c_cur into abc;
    dbms_output.put_line('the senoirs peoples are'||abc.id);
    dbms_output.put_line('the senoirs peoples are'||abc.name);
    dbms_output.put_line('the senoirs peoples are'||abc.age);
    dbms_output.put_line('the senoirs peoples are'||abc.salary);
    dbms_output.put_line('the senoirs peoples are'||abc.gender);
    exit when c_cur%notfound;
    end loop;
    close c_cur;
    end; 

No comments: