开发者

example for using execute block to insert data using parameters for column names

开发者 https://www.devze.com 2023-04-13 01:39 出处:网络
I dont know if this is possible but I am looking for any example using execute block to execute Insert statement and insert data using parameters for column names

I dont know if this is possible but I am looking for any example using execute block to execute Insert statement and insert data using parameters for column names

pseudo code:

  While loop_counter begin

    Insert into table1 (f1+loop_counter, f2+loop_counter, f3+loop_counter, f4+loop_counter)
      values (#,#,#,#)
 end

where开发者_开发百科 "f" is the first initial of the field name and "loop_counter" is a loop variable

Thanks


You need in EXECUTE STATEMENT operator. Try something like this:

EXECUTE BLOCK
AS
  DECLARE VARIABLE s VARCHAR(200);
  ...
BEGIN
  ...
  WHILE (<some condition with loop_counter>) DO 
  BEGIN
    s = 'INSERT INTO TABLE1 (F1' || 
      loop_counter || ', F2' ||
      loop_counter || ',F3' || 
      loop_counter || ',F4' || 
      loop_counter || ') VALUES (?, ?, ?, ?)';
    EXECUTE STATEMENT (:S) (#,#,#,#);
    ...
  END
  ...
END
0

精彩评论

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

关注公众号