Count of rows returned by a cursor



IBM's flagship relational database management system

Count of rows returned by a cursor

Postby ctrevino » Wed Mar 10, 2010 9:51 pm

I am coding a cursor to sum up the data in a number of rows. I need to report a percentage that will be:
100 * sum/number of rows

What is the best way to get a count of the number of rows without doing a separate select? Can I include the count in my cursor declaration? Is this data included somewhere in the SQLCA?

Thanks,
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Count of rows returned by a cursor

 

Re: Count of rows returned by a cursor

Postby ctrevino » Wed Mar 10, 2010 10:47 pm

nevermind
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Count of rows returned by a cursor

Postby dick scherrer » Thu Mar 11, 2010 1:01 am

Hi Christy,

You're too quick for us :)

What did you decide to use?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Count of rows returned by a cursor

Postby avik1983 » Thu Mar 11, 2010 12:22 pm

Christy,
Please let us know what the best usage considering optimum performance u achived.Because usage of COUNT(*) will be pathetic for large number of rows :roll: :roll:
avik1983
 
Posts: 3
Joined: Thu Mar 11, 2010 11:59 am
Has thanked: 0 time
Been thanked: 0 time

Re: Count of rows returned by a cursor

Postby ctrevino » Thu Mar 11, 2010 9:29 pm

well, my manager decided not to rewrite the IMS to a DB2 program (we are propagating some data and in this case I was going to use the propagated data). I was looking at the number returned in SQLERRD (3) and see if it worked for fetch only cursors and not just updates.
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Count of rows returned by a cursor

Postby GuyC » Fri Mar 12, 2010 2:41 pm

sqlerrd(3) does not work for cursors.
In DB2 9 you can use OLAP functions.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Count of rows returned by a cursor

Postby ctrevino » Fri Mar 12, 2010 9:36 pm

Thanks, Guy. Good to know.
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post