在我的存储过程中,要执行一条动态sql,将数据插入到另个一用户下的表中。
通过显示授权后,依然报以下错误。
ORA-01031: 权限不足
ORA-06512: 在 line 1
ORA-06512: 在 "RULE_ENGINE.RULE_ENGINE", line 51
ORA-06512: 在 line 2
后来想到,在存储过程中加入authid current_user时存储过程可以使用当前用户的role权限,于是就修改为
create or replace package body rule_execute is
procedure execute_rule(scheme_code varchar2,
month_no number) authid current_user is
......
但编译时又报错
PLS-00157: AUTHID only
allowed on schema-level programs
查了下错误原因 An AUTHID clause was specified for a subprogram inside a
package or type. These clauses are only supported for top-level
stored procedures, packages, and types.
大致意思就是authid只能用在顶级的存储过程、包、类型上,不能用在包或类型的子程序上。
于是在包上加入authid,执行正常了。
create or replace package rule_execute
authid current_user
is
...
注意:这里是加在了包声明中,而非包体(package body)上。包体上不用加,否则编译时还是报错。