473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

To get the number of rows affected by a cursor open

2
Hi,

I have a cursor opened by a PREPARE statement. I need the total number of rows whcih will be fetched by that cursor. Now I am taking the total number by a COUNT(*) of that dynamic SQL. As COUNT(*) affects the performance, I would like to get the same along with the PREPARE statement.

Will any value in the SQLERRD table gives the total number fetched ? If so please specify how it can be done.

Thanks
Arun
May 17 '07 #1
2 6821
frozenmist
179 Expert 100+
Hi Arun,
If you want to know when to stop fetching,then you can use this method also.
you can declare a continue handler for not found and assign a flag some value.
After fetching check the flag value and then give subsequent statements.
eg:

Expand|Select|Wrap|Line Numbers
  1. declare flag integer;
  2. declare continue handler for not found
  3. begin
  4. set flag= -1;
  5. end;
  6. ......
  7. set flag=0;
  8. <open your cursor>
  9. while(flag=0)
  10. fetch <cursor> into <variables>;
  11. if (flag=0) then <your statements> end if;
  12. end while;
  13. <close your cursor>
  14.  
When no more rows are there NOT FOUND exception will be raised. As it is a continue handler, it will continue execution from next line.
So until flag value is -1 the fetching continues.

Hope you got it..
Cheers
May 17 '07 #2
gkarun
2
Hi frozenmist,

That will not solve my problem. I want to know whether any register value or so is there to store the total number of matching rows for a SELECT query.
Suppose my SELECT query select 100 rows from a 1000 row table, is there any system managed code (like SQLCODE or SQLERRD) contains the value 100 there.
I referred the following link.
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/db2/rbafzmstfielddescsqlca.htm

But SQLERRD(3) is not giving me the expected value when I displayed after the PREPARE Statement which prepares my SELECT query.
Do you have any suggestion on it ?

Thanks
Arun
May 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
19
by: xixi | last post by:
i want to use sql query to open a resultset, say i want the cursor point to whatever position i start with by giving a row number , so is there anyway i can use the sql function to do that, so...
1
by: BF | last post by:
Hello, I am trying to find out if there is a way to limit the number of rows returned when a cursor is opened. I am using DB2 version 7 on z/OS. The SELECT statement in my DECLARE CURSOR...
3
by: Christoffer Gurell | last post by:
After declaring a cursor. Is there any way you can check the number of rows that cursor contains ?? / Christoffer Gurell ---------------------------(end of...
1
by: Phil Endecott | last post by:
Dear Postgresql experts, According to the documentation for MOVE, it returns the number of rows that it has moved over. It seems to me that this is true for MOVE FORWARD n, but not for MOVE...
8
by: surya | last post by:
hi all i hava eetable that is , eename sal _______ ________ suresh 100000 ramsesh 100000 raja 100000 susjssj 100000 dkddkd ...
3
by: Carl K | last post by:
using MySQLdb, I do cursor.execute("update...") How can I tell how many rows were affected ? Carl K
8
by: trint | last post by:
I have a select statement that all I want to do is get the number of rows returned in my query: string strSQLAccountInfo1 = "select * " + "FROM orders " + "where user_id = '" +...
3
by: senthilnova | last post by:
hi all i have c# class which calls a stored procedure having insert,update and delete method (using if to switch between them). when i call the SP to EXECUTENONQUER() there is no response from...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.