如何在立即执行时将 table 名称添加到动态查询中?
How to add table name into dynamic query in execute immediate?
我很困惑,因为我不知道如何在 execute immediate
子句中将变量用作字符串。
declare
variable1 varchar2(30):
cur sys_refcursor;
begin
open cur for
select tablename from table1;
loop
fetch cur into variable1;
exit when cur %notfound;
execute immediate 'select count(*)
into variable1
from user_tables
where table_name =''' || variable1 || '''';
end loop;
close cur;
end;
这里variable1
是一个table名字。应该有一个字符串值。怎么做?仍然有错误。
立即执行语句应如下所示:
execute immediate 'select count(*) from user_tables where table_name ='''||variable1||'''' into variable1;
查询后用into xxx
我很困惑,因为我不知道如何在 execute immediate
子句中将变量用作字符串。
declare
variable1 varchar2(30):
cur sys_refcursor;
begin
open cur for
select tablename from table1;
loop
fetch cur into variable1;
exit when cur %notfound;
execute immediate 'select count(*)
into variable1
from user_tables
where table_name =''' || variable1 || '''';
end loop;
close cur;
end;
这里variable1
是一个table名字。应该有一个字符串值。怎么做?仍然有错误。
立即执行语句应如下所示:
execute immediate 'select count(*) from user_tables where table_name ='''||variable1||'''' into variable1;
查询后用into xxx