Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursors

Status
Not open for further replies.

vijuvelu

Programmer
Nov 7, 2000
8
US
Can anyone give me a example on how to build a cursor with the attribute of another cursor,
for eg:
if cursor1 is
select emp_id, emp_name from emp;
I want to build cursor2 which is select dept_no, dept_name from dept where emp_id = cursor1.emp_id.
Thanks!
 
Two (maybe more) interpretations:
1. Find the first emp_id from cursor1 and use that emp_id in cursor2.
Fetch empid into a variable and use that variable in cursor2.
2. Find all the emp_id's from cursor 1 and find all the depts that correspond.
Fetch the emp_id's into an array, or write them to a temp table.
Rewrite cursor 2 to be an in condition, rather than an = condition. Jim

oracle, vb
 
You may declare parameter for your second cursor:

cursor cursor2(pid number) is select dept_no, dept_name from dept where emp_id = cursor1.emp_id

and then to open it, passing any value you need, e.g. your 1st cursor field value.


 
Thank you Sem and Jim.

What I did was:
Create cursor2(pid in number) is select dept_no, dept_name
from dept where emp_id = pid;

and then opened it passing the 1st cursor value,
ie, open cursor2(cursor1.emp_id);

It Worked!
-Viju. *:->*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top