If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Number of cursor rows returned??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-10, 10:24
jawalker jawalker is offline
Registered User
 
Join Date: Apr 2010
Posts: 1
Number of cursor rows returned??

Is there a DB2 variable that can be accessed via COBOL program to find the number of rows returned in a cursor?
Besides physically counting while fetching,
Reply With Quote
  #2 (permalink)  
Old 04-20-10, 12:41
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
i don't know any other ways of doing it, but running a statement "select count(*) ..." with same 'where' clause before your cursor statement.
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #3 (permalink)  
Old 04-20-10, 13:40
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by jawalker View Post
Is there a DB2 variable that can be accessed via COBOL program to find the number of rows returned in a cursor?
Besides physically counting while fetching,
Obviously, the number of rows returned in a cursor is not known until all of them are processed, so you might just as well count them.
Reply With Quote
  #4 (permalink)  
Old 04-20-10, 15:04
schintala schintala is offline
Registered User
 
Join Date: Apr 2005
Location: USA
Posts: 119
I remember using one of the SQLCA variable to get no of rows effected by SQL execution. Just look at this variable SQLERR(3) from this cobol structure.


01 SQLCA SYNC.
05 SQLCAID PIC X(8) VALUE "SQLCA ".
05 SQLCABC PIC S9(9) COMP-5 VALUE 136.
05 SQLCODE PIC S9(9) COMP-5.
05 SQLERRM.
05 SQLERRP PIC X(8).
05 SQLERRD OCCURS 6 TIMES PIC S9(9) COMP-5.
05 SQLWARN.
10 SQLWARN0 PIC X.
10 SQLWARN1 PIC X.
10 SQLWARN2 PIC X.
10 SQLWARN3 PIC X.
10 SQLWARN4 PIC X.
10 SQLWARN5 PIC X.
10 SQLWARN6 PIC X.
10 SQLWARN7 PIC X.
10 SQLWARN8 PIC X.
10 SQLWARN9 PIC X.
10 SQLWARNA PIC X.
05 SQLSTATE PIC X(5).
Reply With Quote
  #5 (permalink)  
Old 04-20-10, 15:18
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
"rows effected" only includes inserts, updates, or deletes.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 04-21-10, 05:35
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
As Nick said, there is often no way for DB2 to know the number of rows ahead of time. The only option would be to materialize the result and then count it. It does not matter if DB2 does the counting or the application - the query has to be executed twice (which is really bad performance-wise) or you have to count while fetching the rows. So if you do not care about performance, do the SELECT COUNT(*) approach.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 04-21-10, 06:26
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by schintala View Post
I remember using one of the SQLCA variable to get no of rows effected by SQL execution. Just look at this variable SQLERR(3) from this cobol structure.
Thats right. I've coded in the past:
Code:
perform cursor-open.
perform SQLERR(3) times
   perform cursor-fetch
   perform process-cursor-data
end-perform.
perform cursor-close.
Not the most robust example, but it works

Concerning the rows-affected: be aware that cascade-deletes are not included.
Reply With Quote
Reply

Tags
db2 cursor fetch

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On