How to reference field names with variable in Firebird stored procedure or execution block

前端 未结 1 511
迷失自我
迷失自我 2020-12-22 02:15

Please give me an example how to reference field names with variable in a Firebird stored procedure or execute block

Something like this pseudo SQL:

相关标签:
1条回答
  • 2020-12-22 03:06

    It's still not quite clear to me what you want to achieve, but in the PSQL there is also EXECUTE STATEMENT feature available which might suit your needs - it allows you to buid a string and then execute it as a DSQL statement... Assuming the var_loop in your example is integer your code might be something like

    CREATE PROCEDURE Foo(var_loop INTEGER)
    AS
    DECLARE Stmnt VARCHAR(1024);
    BEGIN
      Stmnt = 'Insert into tab1 (1, f1, f2, f3)'||
              'select 1, tab2.f'|| CAST(var_loop AS VARCHAR(10)) ||
              ', tab2.f'|| CAST(var_loop AS VARCHAR(10)) ||
              ', tab2.f'|| CAST(var_loop AS VARCHAR(10)) ||
              'from tab2 where(...)';
      EXECUTE STATEMENT Stmnt;
    END^
    
    0 讨论(0)
提交回复
热议问题