Solved

count records in cursor  + PL/SQL

Posted on 2007-12-04
4
7,004 Views
Last Modified: 2013-12-07
Hi, I have a question about cursor.
I have a cursor, How can I know is there any record in it instead of Fetch the records?
like:
Open curCht for strSQL;
How do I know there are records in this cursor?

Thanks
0
Comment
Question by:chenjhua
  • 2
4 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 20405515
Hi,
I dont think there is any way you can get the count just after opening the cursor.

You can use BULK_COLLECT feature of cursor which will should give the desired resutls you are looking for.

Thanks,
ajexpert
0
 

Author Comment

by:chenjhua
ID: 20405633
ajexpert:
thanks for the answer. Can you give mw detail about it?
basically, I will execute a sql to get a cursor, and I will return this cursor to the Front end, before I return it, I need know is there any record in that cursor.

Thanks
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 20405701
OK...what I understand is that you need to do some processing if there are records in cursor else you dont have to do any processing.

Also do you wish to return the cursor to the front end? If yes, I believe there is no issue if there are no records in it.
This condition (i.e no records in cursor) can be handled very well in backend as well as in front end.
Do let me know how do you wish to incorporate.

Thanks
0
 
LVL 13

Accepted Solution

by:
anand_2000v earned 125 total points
ID: 20405862
A good example was given in another question asked just a few hours back
create or replace

PROCEDURE COUNTER AS

 

TYPE v_array is varray(100000) of NUMBER(38,8); 

temp_array V_ARRAY;

 

CURSOR nwr is SELECT x_coord from GRID_FLORIDA g,f_region r where r.region_id = 'R108' and sdo_relate(g.geom, r.geom,'mask=ANYINTERACT querytype=WINDOW') = 'TRUE';

 

begin 

open nwr;

  fetch nwr bulk collect into temp_array;

  Dbms_output.PUT_LINE(temp_array.count);

close nwr;

END COUNTER;

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now