Solved

count records in cursor  + PL/SQL

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

786 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