一个简单问题:如何利用存储过程执行表字段中的sql语句?

2024-07-27 12:56:34
推荐回答(2个)
回答1:

用游标就行了
declare
cursor cc is select sql_text from A; --声明游标
ccrec cc%rowtype; --声明游标变量
begin
open cc;
loop --循环取数
fetch cc into ccrec;
exit when cc%notfound; --取不到数迹掘退出
begin
EXECUTE IMMEDIATE 'insert into B(result) '|| ccrec.sql_text; --执行盯裤把查询凯州简结果插入B表语句
end;
end loop;

close cc;
end;

回答2:

应该类似动态SQL执行吧