2013-04-23 59 views
1

當我嘗試執行下面的查詢即時通訊錯誤在第4行如「 ORA-06512:在第5行」,其中「樣本」是動態全局臨時表。動態查詢錯誤

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

如果(cnt)> 0,那麼改變這個如果cnt> 0然後 – Satya 2013-04-23 09:14:51

回答

4

變量需要外部的執行直接指定:

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

但只要表名是不是動態的,你可以做同樣的事情立即執行:

begin 
    select count(*) into cnt from sample; 
    ... 
+0

Nyffenegger - 你太棒了,非常感謝你 – user1990383 2013-04-23 09:24:40