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 > How to get record count?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-05, 12:47
sordax sordax is offline
Registered User
 
Join Date: Feb 2005
Posts: 12
How to get record count?

Is there any way to get the number of records selected when I declare a cursor without fetching all those records or doing a select count(*)... ?
Reply With Quote
  #2 (permalink)  
Old 02-25-05, 12:56
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
AFAIK, it is not possible ..

Under certain circumstances, you may be able to start fetching from the cursor, even before the materialization of the cursor is complete .. Example: Select all rows in table

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 02-25-05, 12:59
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If you have a cursor, DB2 sometimes tries not to read (materialized in a temp table) the entire cursor until you fetch each specific row. Therefore, DB2 may not know how many rows there are in the cursor until you fetch them all (although sometimes it does, especially if you have an ORDER BY).

In cases where the cursor is not materialized, the rows in the cursor are not locked until fetched, so they could be deleted before you access them (or more rows could be inserted).
__________________
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
  #4 (permalink)  
Old 02-25-05, 13:00
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
I should have taken an IX lock on this thread before sathyaram_s posted.
__________________
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
  #5 (permalink)  
Old 02-25-05, 17:36
sordax sordax is offline
Registered User
 
Join Date: Feb 2005
Posts: 12
Ok, thanks guys.
Reply With Quote
  #6 (permalink)  
Old 02-25-05, 18:06
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If you are working with DB2 for i-series, you should state that. Everyone should state which OS and DB2 version they are working with, but it is even more important for i-series because it is often different from the other DB2's.
__________________
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
Reply

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