当我尝试执行以下查询时,我在第4行获取错误,如“ ORA-06512:在第5行“,其中”sample“是动态全局临时表。
declare max_seq_dp varchar2(20);
cnt number(20);
begin
execute immediate 'select count(*) into cnt from sample';
dbms_output.put_line(cnt);
if (cnt)>0 then
begin
select max(sequence_number) into max_seq_dp
from sample1 where column1 = '2045'
and is_active = 1;
dbms_output.put_line(max_seq_dp);
end;
end if;
end;
谢谢
答案 0 :(得分:4)
需要在execute immediate:
之外指定变量 execute immediate 'select count(*) from sample' into cnt;
但是只要表名不是动态的,你就可以做同样的事情没有立即执行:
begin
select count(*) into cnt from sample;
...