对于本地的用户,执行INSERT操作只需要INSERT权限,而只有INSERT权限这对于通过数据库链执行插入操作是不够的。



看Oracle的管理员手册是发现了这个问题,以前还确实没有注意过。

看一个具体的例子,首先在本地建立一个普通用户,并将表T的INSERT、UPDATE和DELETE权限授权给这个用户:

SQL> show user    


USER is "TEST"


SQL> create table t (id number);


Table created.


SQL> create user u1 identified by u1;


User created.


SQL> grant create session to u1;


Grant succeeded.


SQL> grant insert, update, delete on t to u1;


Grant succeeded.


SQL> conn u1/u1


Connected.


SQL> insert into test.t values (1);


1 row created.


SQL> update test.t set id = 2;


1 row updated.


SQL> delete test.t;


1 row deleted.


SQL> commit;


Commit complete.


在本地执行,用户U1可以对T表执行INSERT、UPDATE和DELETE的操作。

下面在远端建立数据库链,使用U1作为连接用户:

SQL> select * from global_name;


GLOBAL_NAME


--------------------------------------------------------------------------------


TESTRAC


SQL> create database link test08


 2  connect to u1


 3  identified by u1


 4  using '172.25.13.229/test08';


数据库链接已创建。


SQL> select * from global_name@test08;


GLOBAL_NAME


--------------------------------------------------------------------------------


TEST08


SQL> insert into test.t@test08 values (1);


insert into test.t@test08 values (1)


                *


第1行出现错误:


ORA-01031: insufficient privileges


ORA-02063:紧接着line (起自TEST08)



SQL> update test.t@test08 set id = 1;


update test.t@test08 set id = 1


           *


第1行出现错误:


ORA-01031: insufficient privileges


ORA-02063:紧接着line (起自TEST08)



SQL> delete test.t@test08;


delete test.t@test08


           *


第1行出现错误:


ORA-01031: insufficient privileges


ORA-02063:紧接着line (起自TEST08)


这是由于通过数据库链访问远端对象的时候,Oracle需要查询权限来对表结构进行分析,因此如果是通过数据库链执行DML操作,除了对应的DML权限外,用户还需要SELECT权限。

SQL> conn test/test


Connected.


SQL> grant select on t to u1;


Grant succeeded.


有了SELECT权限,通过数据库链执行DML就可以顺利执行了:

SQL> insert into test.t@test08 values (1);


已创建1行。


SQL> update test.t@test08 set id = 2;


已更新1行。


SQL> delete test.t@test08;


已删除1行。


SQL> commit;


提交完成。


SQL> select * from test.t@test08;


未选定行


oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html