Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Posts
    12

    Unanswered: 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(*)... ?

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

  4. #4
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

  5. #5
    Join Date
    Feb 2005
    Posts
    12
    Ok, thanks guys.

  6. #6
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •