How to SELECT a PROCEDURE in Firebird 2.5

前端 未结 8 1346
误落风尘
误落风尘 2021-01-11 23:21

I\'m using Firebird Embedded v2.5. How to use procedures in query (SELECT) ?

My procedure:

SET TERM ^ ;
CREAT         


        
相关标签:
8条回答
  • 2021-01-11 23:32

    As JustMe said, you can't call stored procedures in a select. You can call stored procedure only in the FROM section. Another solution for your problem is to create a selectable procedure like this:

    create or alter procedure myproc (
     n integer)
    returns (
     field_1 integer,
     zzz integer,
     field_2 integer,
     modified_field_2 integer)
    as
    declare variable i integer;
    begin
      for
        select some_table_field_1, :n+1 as zzz, some_table_field_2, (some_table_field_2+1) as field_2_modified
        from tb_test
        into :field_1, :zzz, :field_2, :modified_field_2
      do begin
        suspend;
      end
    end
    

    After run that code, you can simply query select * from myproc(4) and get what you want.

    0 讨论(0)
  • 2021-01-11 23:33

    Try this

    SET TERM ^ ;
    CREATE PROCEDURE FN_TEST( Y INTEGER )
    RETURNS( X INTEGER)
    AS
    BEGIN
    X = Y + 1;
    SUSPEND;
    END^
    SET TERM ; ^
    
    0 讨论(0)
  • 2021-01-11 23:38
    SELECT some_table_field_1, 
       (select X from fn_test( 4 )) AS zzz, 
       some_table_field_2,
       (select X from fn_test( some_table_field_2 )) AS field_2_modified
    FROM   tb_test
    
    0 讨论(0)
  • 2021-01-11 23:38

    Try

    SELECT some_table_field_1, 
       fn_test.x AS zzz, 
       some_table_field_2,
    FROM   tb_test
    LEFT JOIN fn_test(some_table_field_1) ON (1 = 1)
    
    0 讨论(0)
  • 2021-01-11 23:40

    You can use EXECUTE BLOCK Please have a look EXECUTE BLOCK

    0 讨论(0)
  • 2021-01-11 23:46

    You can't call stored procedures in Firebird's select list. You have to write the selectable procedure with desire result or write an UDF function to do what you have in fn_test procedure.

    For your case the simplest way is:

    SELECT some_table_field_1, 
           5 AS zzz, 
           some_table_field_2,
           ( some_table_field_2 + 1) AS field_2_modified
    FROM   tb_test
    
    0 讨论(0)
提交回复
热议问题