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.

Using a Cursor Expression


DECLARE

TYPE emp_cur_typ IS REF CURSOR;

emp_cur EMP_CUR_TYP;

dept_name departments.department_name%TYPE;

emp_name employees.last_name%TYPE;

CURSOR c1 IS

SELECT department_name,

-- second item in the result set is another result set,

-- which is represented as a ref cursor and labelled "employees".

CURSOR (SELECT e.last_name

FROM employees e

WHERE e.department_id = d.department_id) employees

FROM departments d

WHERE department_name LIKE 'A%';

BEGIN

OPEN c1;



LOOP

FETCH c1 INTO dept_name,emp_cur;



EXIT WHEN c1%NOTFOUND;



dbms_output.Put_line('Department: '

||dept_name);



-- for each row in the result set, the result set from a subquery is processed

-- the set could be passed to a procedure for processing rather than the loop

LOOP

FETCH emp_cur INTO emp_name;



EXIT WHEN emp_cur%NOTFOUND;



dbms_output.Put_line('-- Employee: '

||emp_name);

END LOOP;

END LOOP;



CLOSE c1;

END;

/




Output :-

Department: Administration
-- Employee: Whalen
Department: Accounting
-- Employee: Higgins
-- Employee: Gietz

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 :-