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 > fiind rowcount in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-10-10, 09:20
lazydev lazydev is offline
Registered User
 
Join Date: Mar 2010
Posts: 15
fiind rowcount in db2

This is what i do in sqlserver to find the number of affteced rows.

UPDATE authors SET city = 'Oakland' WHERE city = 'Salt Lake City'
SELECT @@rowcount AS 'RowsChanged'


What's the alternate option for the same process in db2 .
with out using select count(*) from statements .
can we find the same using any handlers in stored procedures .
Reply With Quote
  #2 (permalink)  
Old 05-10-10, 12:09
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
in the sqlca, sqlerrcd(3) contains a count of
  • rows read
  • rows inserted
  • rows updated
  • rows deleted
for an execution of a particular sql.
__________________
Dick Brenholtz, Ami in Deutschland
Reply With Quote
  #3 (permalink)  
Old 05-11-10, 08:44
lazydev lazydev is offline
Registered User
 
Join Date: Mar 2010
Posts: 15
I have gone through some IBM articles and it says it works if i keep the include option for geeting the sqlca .

I am unable to get the same in stored procedures .

Can you provide me a sample piece of code using the sqlca option .
Reply With Quote
  #4 (permalink)  
Old 05-11-10, 08:50
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
may be...

GET DIAGNOSTICS SQL-variable-name = ROW_COUNT;
Reply With Quote
  #5 (permalink)  
Old 05-12-10, 04:28
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or you do a "SELECT COUNT(*) FROM NEW TABLE ( UPDATE ... )"
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 05-12-10, 04:47
lazydev lazydev is offline
Registered User
 
Join Date: Mar 2010
Posts: 15
GET DIAGNOSTICS SQL-variable-name = ROW_COUNT;

this works fine for me and i am done .

but I would like to check how to use sqlca in db2 procedures .
Reply With Quote
  #7 (permalink)  
Old 05-12-10, 06:12
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
the sqlca is used in a stored procedure as in any other program:



/* this is a stored procedure for test purpose */
dbsp03: proc (parm1) options(main noexecops);

dcl h bin fixed(31) init (123);

exec sql include sqlca;

exec sql delete from my.table where col > :h ;

if sqlca.sqlcode ^= 0 & sqlca.sqlcode ^= 100 then do;
call your_error_routine();
end;

put skip edit ('----------- DBSP03 (REPORT) ----------') (A);
put skip edit (' Number of records deleted: ', SQLCA.SQLERRD(3) ) (A,A);
put skip edit ('----------- DBSP03 (REPORT END) -------') (A);

end dbsp03 ;


Note: The number of records affected by the statement is stored in the variable SQLERRD(3), not -as dbzTHEdinosaur mentioned- in SQLERRCD(3)


if your program language is C, the number is stored in sqlerrd[2]

Last edited by umayer; 05-12-10 at 06:19.
Reply With Quote
  #8 (permalink)  
Old 05-12-10, 10:08
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
umayer,

your are correct and I apologize for not referring to the manual for proper spelling before posting.
__________________
Dick Brenholtz, Ami in Deutschland
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