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
