求解动态SQL难题
在下遇到一个难题,需要从表中读取3个字段 分别存放的declare statement,赋值语句和控制语句,以及DML语句, 然后将3部分拼接起来动态执行,例如:表中3个字段某行内容 col1: declare a int; declare b int;
col2: if m>0 then set a=1; set b=2; else set a=1;set b=1; end if;
col3: values(a,b)
现在需要在存储过程中读取这3个字段内容:select col1,col2,col3 into a,b,c from tab where id=xx;
然后想办法动态的组装这3部分 并执行 set t='begin '|| a || b || ' insert into test1 '|| c ||' ; insert into test2 '||c ||'; end';
但是现在有2个问题: DB2好像不支持在动态SQL里包含类似IF ELSE的控制语句;另外好像也不支持多个DML或者select操作放在一起
求教各位高手,如何能达到这个目的?环境是db2 v97 for windows 回复 1# onlyzz
case when 好像不行,看错题了。
页:
[1]