2013-12-19 138 views
7

我正在使用Oracle 11.2.0.1.0,並試圖讓dbms_sql包正常工作。 不過,我不斷收到ORA-29471錯誤,如下圖所示:如何解決dbms_sql.open_cursor上的ORA-29471?

DECLARE 
    c INTEGER; 
BEGIN 
    c := dbms_sql.open_cursor(); 
END; 

ORA-29471: DBMS_SQL access denied 
ORA-06512: at "SYS.DBMS_SQL", line 1017 
ORA-06512: at line 4 

神諭docs說以下這一點:綁定及執行時

檢查完成。可選地,對每個單個DBMS_SQL子程序調用執行的檢查可能是 。該檢查是:

  • current_user在調用子程序時與調用最近解析時相同。
  • 調用子程序時啓用的角色必須是調用最近解析的啓用角色的超集。

與使用定義者權限子程序一致,角色不適用 適用。如果任一檢查失敗,並且引發ORA-29470錯誤。

據我所知,這兩個條件不適用於我的代碼,因爲代碼不跨架構。

Oracle support(需要登錄)網站建議我將security_level參數顯式添加到dbms_sql.open_cursor中。添加任何值(0/1/2)都不能解決問題。

對我來說令人費解的是,我在dbms_sql.open_cursor處得到了錯誤,這是安全級別首次定義的地方。

的支持網站還提出了一種變通方法,包括設置:

alter system set "_dbms_sql_security_level" = 384 scope=spfile; 

我還沒有試過呢。我更喜歡將其視爲最後的手段,因爲它涉及到禁用安全層並且它是不受支持的oracle功能。幾乎不適合生產使用的情況。此外,它並不真正解決問題,只是隱藏它。

我該如何解決這個錯誤?

回答

9

的唯一原因(不能看到另一個在這一刻),爲什麼你的代碼引發ORA-29471是你已經在你的會話提供一個無效的光標ID發dbms_sql無法使用:

/* dbsm_sql detects invalid cursor ID in this session */ 
SQL> declare 
    2 c_1 number := 5; -- invalid cursor ID. There is no cursor 
    3 l_res boolean; -- opened with ID = 5  
    4 begin 
    5 l_res := dbms_sql.is_open(c_1); 
    6 end; 
    7/
declare 
* 
ERROR at line 1: 
ORA-29471: DBMS_SQL access denied 
ORA-06512: at "SYS.DBMS_SQL", line 1104 
ORA-06512: at line 5 


/* An attempt to execute this simple anonymous PL/SQL block after 
    an invalid cursor ID has already been detected by the dbms_sql 
    in the current session will lead to ORA-29471 error 
*/ 

SQL> declare 
    2 c_2 number; 
    3 begin 
    4 c_2 := dbms_sql.open_cursor(); 
    5 end; 
    6/
declare 
* 
ERROR at line 1: 
ORA-29471: DBMS_SQL access denied 
ORA-06512: at "SYS.DBMS_SQL", line 1084 
ORA-06512: at line 4 

嘗試執行代碼在新成立的會議上。

+1

該死的。我準備說完全一樣的東西,但是你打敗了我。 +1 –

+1

我剛剛以與您相同的方式重新聲明瞭錯誤,並且當我看到您的答案時即將粘貼SQL * Plus輸出到我的答案中。如果我對此感到不安,我就不會提高你的帖子。 :) –

+1

你是對的。建立一個新的會議解決了這個問題。我無法相信我花了一個多小時纔沒有發現。謝謝! –