4.读取远端数据表中数据,但是访问本地序列。
SQL> insert into test_on_yangtk@yangtk select seq_on_test4.nextval from test_on_yangtk@yangtk;
insert into test_on_yangtk@yangtk select seq_on_test4.nextval from test_on_yangtk@yangtk
*
ERROR 位于第 1 行:
ORA-02289: 序列(号)不存在
ORA-02063: 紧接着line(源于TEST4)
ORA-02063: 紧接着2 lines(源于YANGTK)
根据测试,第一种情况和第四种情况出现了相同的错误。
在和其他所有没有报错的情况比较后,可以得到这样的结论:当插入远端数据表,并使用本地序列时会出现错误。
Oracle的error文档上这样描述2289错误的:
ORA-02289 sequence does not exist
Cause: The specified sequence does not exist,
or the user does not have the required
privilege to perform this operation.
Action: Make sure the sequence name is correct,
and that you have the right to perform
the desired operation on this sequence.
根据目前的错误以及Oracle给出的错误原因,初步怀疑对于这种插入远端数据表的分布式事务,实际上是在远端上执行的。因此YANGTK上的scott用户找不到SEQ_ON_TEST4这个序列。
给YANGTK上的scott用户增加一个指向TEST4上yangtk用户的数据库链。
SQL> conn scott/tiger@yangtk
已连接。
SQL> create database link test4 connect to
yangtk identified by yangtk using 'test4';
数据库链接已创建。
SQL> conn yangtk/yangtk@test4
已连接。
SQL> insert into test_on_yangtk@yangtk select
seq_on_test4.nextval from test_on_test4;
已创建 1 行。
SQL> rollback;
回退已完成。
SQL> insert into test_on_yangtk@yangtk select
seq_on_test4.nextval from test_on_yangtk@yangtk;
已创建 1 行。
SQL> rollback;
回退已完成。
在建立数据库链之后,重新执行错误的语句,这次执行没有出现错误。
总结:
假如在一条语句中同时使用数据库链和序列,大家需要注意的是:目前可能不仅需要一条到远端的数据库链,还可能同时需要一个从远端到本地的数据库链.