通过动态替换变量值来执行存储在表列中的选择语句
我有一个简单的PL/SQL块,下面的代码
declare
rule1 varchar2(100 char);
begin
for i in (select table_name from all_tables where table_owner='EqEDI') loop
execute immediate 'select rule_stmt from rulebook ' into rule1 ;
execute immediate rule1 into result;
dbms_output.put_line('Result is '||result);
end loop;
end;
在表格规则手册中存储的规则语句是:
"'select count(1) from '|| <tablename>"
我希望以上所有的表为给定所有者的所有表执行此上述语句 但是在执行时,它不会用实际表中的查询中替换 。 如何使用简单的PL/SQL块实现它。
I have simple PL/SQL block with below code
declare
rule1 varchar2(100 char);
begin
for i in (select table_name from all_tables where table_owner='EqEDI') loop
execute immediate 'select rule_stmt from rulebook ' into rule1 ;
execute immediate rule1 into result;
dbms_output.put_line('Result is '||result);
end loop;
end;
the rule statement stored in table rulebook is :
"'select count(1) from '|| <tablename>"
I want this above statement to be executed for all tables present for given owner
but while executing, it does not replace in query with actual tables.
How can I achieve it with simple PL/SQL block.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
规则手册
表的内容有点像错误。并不是说您无法按照存储选择
语句进行操作 - 它只是不切实际的,因为您必须删除单个报价,删除tablename
(因为您无法甚至可以绑定它,但会使光标返回的内容加入……太多不必要的工作要做。另外,请检查
all_tables
及其列的名称 - 没有table_owner
,只有所有者
。因此,我建议您存储这样的声明:
修复您的PL/SQL脚本:
rulebook
table's contents is kind of wrong. Not that you can NOT do it the way you storedselect
statement into it - it is just impractical as you have to remove single quotes, removetablename
(as you can't even bind it, but concatenate what cursor returned) ... too much unnecessary jobs to be done.Also, check
all_tables
and names of its columns - there's notable_owner
, justowner
.Therefore, I'd suggest you to store such a statement:
Fix your PL/SQL script: