您的位置:首页 > 职场人生

存储过程里不能访问其他用户的表

2011-05-05 16:19 288 查看
今天遇到一个很奇怪的问题,有两个用户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;

然后再编译就通过了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐