Solved

count records in cursor  + PL/SQL

Posted on 2007-12-04
4
6,999 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

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…
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 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…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now