今天遇到一個很奇怪的問題,有兩個用戶hbibillms和hbibilldata,都是dba角色權限,我現在在hbibillms用戶下建立了一個存儲過程,訪問到hbibilldata用戶下的表:
create or replace procedure test2 is
begin
--p_feetraderecord
insert into hbibilldata.feetraderecordhistory
select *
from hbibilldata.feetraderecord
where TO_CHAR(lastmodifytime, 'yyyy-mm-dd') <=
to_char(ADD_MONTHS(sysdate, -12), 'yyyy-mm-dd');
commit;
delete from hbibilldata.feetraderecord
where TO_CHAR(lastmodifytime,'yyyy-mm-dd')<=
to_char(ADD_MONTHS(sysdate,-12),'yyyy-mm-dd');
commit;
end test2;
編譯時報錯,說hbibilldata.feetraderecord和hbibilldata.feetraderecordhistory表或視圖不存在。
我將這兩句摳出來,放到sql窗口實行了下,沒問題,可以訪問的,可是爲什麼到了存儲過程裏面就找不到了呢?
在網上查了下,找到問題的根源了:
“在oracle的pl/sql塊(過程、函數和包也是命名pl/sql塊)中對數據的訪問權限和單純在sqlplus中有時候是不一樣的,塊中訪問數據必須通過顯式授權,也就是通過grant ... to userxxx的方式而不是通過隱式方式(通過role授權)。檢察權限分配,就應該能解決問題了”
我試着爲hbibillms用戶顯示分配了對這兩張表的操作權限:
grant select,update,delete,insert on hbibilldata.feetraderecord to hbibillms;
grant all on hbibilldata.feetraderecordhistoryto hbibillms;
然後再編譯就通過了。