Solved

count records in cursor  + PL/SQL

Posted on 2007-12-04
4
7,021 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

636 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