I have the following table
create table LIST_PIPE_TABLE
(
ID INT,
ITEM VARCHAR(4000),
IS_FOLDER VARCHAR(10)
)
with 3 rows of data
insert into LIST_PIPE_TABLE values(1,'Victorias Secret','true')
insert into LIST_PIPE_TABLE values(2,'Porsche','true')
insert into LIST_PIPE_TABLE values(3,'Babbolat','false')
And a stored procedure that should return resultset
CREATE or alter PROCEDURE LIST_PIPE
RETURNS
( col1 varchar(4000),
col2 varchar(10)
)
AS
begin
FOR SELECT ITEM AS ITEM
,IS_FOLDER AS IS_FOLDER
FROM LIST_PIPE_TABLE
into :col1, :col2
do begin
suspend;
end
end
When I try to execute it with the following statement
execute procedure LIST_PIPE
the only one top row is returned
COL1 COL2
Victorias Secret true
Please advise what is wrong about it. How should I execute it to see all 3 rows it is designed to return?
When you have
suspend
in stored procedure, it is called "selectable stored sprocedure", and as the name says you select from it, so:As ain already answered, you need to use
SELECT * FROM <your procedure>
for a selectable procedure (that is: it contains aSUSPEND
).The Interbase 6 Embedded SQL Guide (see under InterBase 6.0 Manuals) says:
On a protocol level, an
EXECUTE PROCEDURE
statement will always produce a single row of results (which might be empty), where as aSELECT * FROM <procedure>
will behave the same as a select from a table or view. This means that if a selectable procedure is called withEXECUTE PROCEDURE
, that Firebird itself will fetch only one row from the stored procedure, and then end execution of the procedure.It is unfortunate that it is possible to use
EXECUTE PROCEDURE
with a selectable procedure. The Interbase 6 Language Reference onSUSPEND
explicitly mentions "SUSPEND
should not be used in an executable procedure." (the phrasing is weird, because the presence ofSUSPEND
is what makes it selectable, though here they mean calling it withEXECUTE PROCEDURE
is not advisable).