I tried with FOR loop, still it does not return data.
Main Topics
Browse All TopicsI have explicit cursor in a procedure. Cursor returns no rows. But when I run the query, cursor uses, from sql plus it returns data. I use a hint in the query. The code is like this:
Cursor c1 is
select column1 from table;
Open c1;
Loop
Fetch c1 into column2;
Exit when c1%NOTFOUND;
---
End Loop;
Close c1;
It exits from loop because no data returns from the cursor. Any suggestions!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi vnkurra,
I had experienced the same problem, but could never find the cause, ofcourse, i found the solution..
Solution:
Declare
Cursor c1 is Select column1 from table;
v_c1 c1%rowtype;
BEGIN
FOR v_c1 in (Select column1 from table)
...statements...
...statements...
Exit When v_c1%notfound
END LOOP;
END;
Aalap Sharma
hey vnkurra,
Can you please tell me what is the error that you are getting?
Try showing data on screen using DBMS_OUTPUT.PUT_LINE, in every iteration in the loop.
The first problem that you told me was encountered by me before sometime, and then i changed the code to the above one. It worked. Now what you are saying, is something, different.
I'll have to review the code for further analysis.
I think you will have to use the DBMS_OUTPUT approach to analyse further.
Aalap Sharma :)
Aalap,
I am not getting any error. I have tried the print statement in the loop, it exits the loop in the first iteratioon since the cursor does not return any data. Please note that this issue is in SQL PLUS. The same cursor returns data from SQL Navigator.
Why the cusor does not return data from SQL PLUS! Any ideas on SQL PLus vs SQL Navigator.
Thanks.
hello vnkurra,
Try running the select query of your cursor alone and see what data u r getting.. It is possible that you dont have data in your cursor query and so it must be coming out in the first iteration.
Copy your select query from the cursor and run it in sqlplus... If it returns no data then it is not the cursor problem.
Aalap Sharma :)
Business Accounts
Answer for Membership
by: sandeep_saoPosted on 2004-05-21 at 00:32:11ID: 11124480
It’s strange since what you are doing it absolutely correct. Just try with the for loop it may work
for c1 in cur_emp loop
- Sandeep