Subject Re: [firebird-support] Stored procedure to return multiple rows in a single string
Author Milan Babuskov
Zd wrote:
> I'd be using stored procedures to avoid on-the-fly query processing and speed up execution time.

Query used by EXECUTE STATEMENT is prepared on-the-fly, so that won't
help you much. However, you should really measure how important is this
to you: time taken to parse the query into BLR is usually insignificant
compared to time taken to execute it and fetch the data.

> I thought there would be a way to do this from a stored proc, without a bunch of ugly ifs...

You will need IF's with or without EXECUTE STATEMENT. Example:

create procedure give_me_data(where1, where2, where3)
returns ( id, foo, bar )
as
declare variable stmt varchar(3000);
begin
stmt = "select id, foo, bar from proc";
if (where1 is not null) then
stmt = stmt || ' ' || where1;
if (where2 is not null) then
stmt = stmt || ' ' || where1;
if (where3 is not null) then
stmt = stmt || ' ' || where1;
FOR EXECUTE STATEMENT :stmt INTO :id, :foo, :bar
DO SUSPEND;
end

--
Milan Babuskov
http://www.flamerobin.org