ORACLE動態sql在存儲過程中出現表或視圖不存在的解決方法


Oracle動態sql在存儲過程中出現表或視圖不存在的解決方法 

 

CREATE OR REPLACE PROCEDURE P_test

is

strsql varchar2(2000);

BEGIN

  

   --導入用戶數據數據               

 strsql := 'insert into tabuser (usercode) select us.tabuser.usercode from us.tabuser'

    execute immediate strsql;      

 

EXCEPTION
when others   then
    raise FIND_DATA_EMP;
end P_test;

 

會出現

ORA-00942: 表或視圖不存在

這種情況為

 用戶擁有的role權限在存儲過程是不可用的。遇到這種情況,我們一般需要顯式進行系統權限,如grant create table to suk;但這種方法太麻煩,有時候可能需要進行非常多的授權才能執行存儲過程,實際上,oracle給我們提供了在存儲過程中使用role權限的方法:修改存儲過程,加入Authid Current_User時存儲過程可以使用role權限

 

 

CREATE OR REPLACE PROCEDURE P_test

Authid Current_User

is

strsql varchar2(2000);

BEGIN

  

   --導入用戶數據數據               

 strsql := 'insert into tabuser (usercode) select us.tabuser.usercode from us.tabuser'

    execute immediate strsql;      

 

EXCEPTION
when others   then
    raise FIND_DATA_EMP;
end P_test;

 

http://blog.csdn.net/sscsgss/article/details/4738470


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM