1

当我尝试执行以下查询时,我在第 4 行遇到错误,例如“ORA-06512: at line 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;

谢谢

4

1 回答 1

4

该变量需要在执行立即数之外指定:

execute immediate 'select count(*) from sample' into cnt;

但是只要表名不是动态的,你可以在不立即执行的情况下做同样的事情

begin
   select count(*) into cnt from sample;
   ...
于 2013-04-23T09:14:56.780 回答