Solved

count records in cursor  + PL/SQL

Posted on 2007-12-04
4
7,010 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

856 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