Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Passing a REF CURSOR as a Parameter


DECLARE

TYPE empcurtyp IS REF CURSOR RETURN employees%ROWTYPE;

emp EMPCURTYP;

-- after result set is built, process all the rows inside a single procedure

-- rather than calling a procedure for each row

PROCEDURE Process_emp_cv

(emp_cv IN EMPCURTYP)

IS

person employees%ROWTYPE;

BEGIN

dbms_output.Put_line('-----');



dbms_output.Put_line('Here are the names from the result set:');



LOOP

FETCH emp_cv INTO person;



EXIT WHEN emp_cv%NOTFOUND;



dbms_output.Put_line('Name = '

||person.first_name

||' '

||person.last_name);

END LOOP;

END;

BEGIN

-- First find 10 arbitrary employees.

OPEN emp FOR

SELECT *

FROM employees

WHERE ROWNUM < 11;



Process_emp_cv(emp);



CLOSE emp;



-- find employees matching a condition.

OPEN emp FOR

SELECT *

FROM employees

WHERE last_name LIKE 'R%';



Process_emp_cv(emp);



CLOSE emp;

END;

/




Output :-

-----
Here are the names from the result set:
Name = Donald OConnell
Name = Douglas Grant
Name = Jennifer Whalen
Name = Michael Hartstein
Name = Pat Fay
Name = Susan Mavris
Name = Hermann Baer
Name = Shelley Higgins
Name = William Gietz
Name = Steven King
-----
Here are the names from the result set:
Name = Trenna Rajs
Name = Den Raphaely
Name = Michael Rogers
Name = John Russell

PL/SQL procedure successfully completed.

Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-