Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In stored procedures, how to find out the number of rows returned?

Status
Not open for further replies.

CapsuleCorpJX

IS-IT--Management
Jun 23, 2004
70
US
I want to check if a select statement returned zero rows or not.

How do I check it?

Activity_Count I thought was used to only find out how many rows have been MODIFIED.
 
Hi,
Try this -

select count(*) into :fred
from table_with_rows_perhaps

Then just check the value of :fred

Roger...
 
Actually I'm trying to count the difference between two columns, I'm thinking about this solution:

select count(select benpkg
from :v2.PCM_PMBENGEN
MINUS
select SOURCE_SYSTEM_BNFT_PKG_ID
from :v1.BENEFIT_PACKAGE_ALL) INTO :htemp;

would it work?
 
Hi,
You probably need to use DBC.SYSEXECSQL. Check the manual for a full explanation, but this would allow you the code something like this -

call dbc.sysexecsql('insert into yourtable
select count(*
from (select benpkg
from ' ||:v2.PCM_PMBENGEN
|| ' MINUS
select SOURCE_SYSTEM_BNFT_PKG_ID
from ' || :v1.BENEFIT_PACKAGE_ALL
|| ');');

(Assuming I haven't go a typo in the above), you should be use your variables in your SQL.

Roger...
 
I'd rather stay away from dyn sql.
Will the following work?

select count(*)
INTO :htemp
from
(
<select statement 1>)
MINUS
<select statement 2>
);
 
Hi,
I don't understand "I'd rather stay away from dyn sql"

It's probably the only way you'll get a stored procedure to do what you want.

Roger...
 
ACTIVITY_COUNT is set by *every* DML statement including SELECT.

If you want to check for a select returning no rows within a SP you can use a:

DECLARE CONTINUE HANDLER
FOR NOT FOUND
BEGIN
...
END

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top