我以UserA身份登录并尝试执行以下
alter session set current_schema = UserB;
begin
execute immediate 'Insert into UserB.tablea (c1, c2) values (val1,val2)'
end;
我一直收到此错误
ORA-01031: insufficient privileges
ORA-06512: at line 3
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label.
我确实在UserA上有alter_session特权,并在UserB.tablea上插入UserA作为UserA。有什么想法吗?
答案 0 :(得分:0)
您可能会对“set current_schema = xyz”的内容感到困惑。这只是使您无需在引用另一个模式中的对象时键入用户名,它不会为您提供任何新权限。
SQL> select * from scott.dept;
DEPTNO DNAME LOC OPTION
---------- -------------- ------------- --------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> select * from dept;
select * from dept
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> alter session set current_schema = scott;
Session altered.
SQL> select * from dept;
DEPTNO DNAME LOC OPTION
---------- -------------- ------------- --------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
因此,您需要将UserB.tablea上的授权插入到运行代码的用户。作为测试,只需运行
即可Insert into UserB.tablea (c1, c2) values (val1,val2);
在开始/结束块之外。