开发者

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

开发者 https://www.devze.com 2023-04-12 06:05 出处:网络
Please give me an example how to reference field names with variable in a Firebird stored procedure or execute block

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:

Insert into tab1 (1, f1, f2, f3)
    select 1, tab2.f+var_loop, tab2.f+var_loop, tab2.f+var_loop
    from tab2
    where .....
开发者_运维技巧

where "f" is the first initial of the field name and "var_loop" is a loop variable


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号