简体   繁体   中英

Executing two FOR SELECT statement in SP firebird

Is it possible to have 2 FOR SELECT statement in stored procedure where the 1st statement will display all of its data then the 2nd statement will continue when the 1st statement is done .

I already tried this one:

for select id,date,particular
from TABLE_NAME
  into :id, :date, :particular
do begin
  suspend;
end

for select id,date,payor
from TABLE_NAME
  into :id, :date, :payor
do begin
   suspend;
end

the first statement performs well but the second statement displays some data of the column particular of the 1st statement.

This is possible, but there are two things you need to take into account:

  1. A selectable stored procedure only has one result set, so for the client it is not possible to detect this without some kind of discriminator column.
  2. If you don't reassign a value, the last assigned value is returned for each subsequent row.

This second item is the problem you are having, to solve this, you need to clear the value of particular , eg by adding the line particular = null; between the first and select for select .. block:

for select id,date,particular
from TABLE_NAME
  into :id, :date, :particular
do begin
  suspend;
end

particular = null;

for select id,date,payor
from TABLE_NAME
  into :id, :date, :payor
do begin
   suspend;
end

However if the code in your question is the actual code, you might want to consider using a view instead with two selects combined with union all . This is likely to have less overhead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM