ORA-02069与database link ,synonym,sequence

通过database link ,序列向远程库中表插入数据时。如果使用本地库中的序列时

会遇到ORA-02069: 此操作的 global_names 参数必须设置为 TRUE。

解决方案:使用远程库中的序列。

 

1.scott用户授予report用户对DEPT表的select, insert, update 权限。

SQL> conn scott/tiger
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as scott
SQL> grant select, insert, update on DEPT to REPORT;
Grant succeeded

 

2.report用户建立到scott用户的database link (建database link只是为了模拟问题)

SQL> conn report/report
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as report

SQL> create   database link scott
  2    connect to scott IDENTIFIED by tiger
  3    using 'liangwei';
Database link created

 

3.基于database link  创建dept@scott 表的synonym

SQL> create or replace synonym dept for dept@scott;
Synonym created

 

4.report用户下创建序列DEPTID

SQL> create sequence DEPTID
  2  minvalue 10
  3  maxvalue 1000
  4  start with 30
  5  increment by 1
  6  cache 20;

Sequence created

 

5.用序列DEPTID向新建的同义词 dept中插入数据,出现ORA-02069

SQL> insert into  dept values ( deptid.nextval ,'CODE' ,'BJ');

insert into  dept values ( deptid.nextval ,'CODE' ,'BJ')

ORA-02069: 此操作的 global_names 参数必须设置为 TRUE

 

SQL> show parameter global_names

NAME          TYPE        VALUE
------------- ----------- -----
global_names  boolean     FALSE

 

如果不设置global_names为true能否解决呢。

 

 

6.以scott用户登录创建序列DEPTID
SQL> conn scott/tiger
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as scott

 

SQL>  create sequence DEPTID
  2   minvalue 10
  3   maxvalue 1000
  4   start with 30
  5   increment by 1
  6   cache 20;

Sequence created

 

7.在report用户中删除序列DEPTID

SQL> conn  report/report
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as report

SQL> drop sequence DEPTID;
Sequence dropped

 

8.使用序列在repot用户下为同义词dept插入数据

SQL> insert into  dept values ( deptid.nextval ,'CODE' ,'BJ');
insert into  dept values ( deptid.nextval ,'CODE' ,'BJ')
ORA-02289: 序列不存在

由于report用户下序列DEPTID已经能够删除,所以报错ORA-02289: 序列不存在

 

 

9.通过database link 使用scoot用户的序列,向report用户中的同义词dept插入数据,ok

 

SQL> insert into  dept values ( deptid.nextval@scott ,'CODE' ,'BJ');
1 row inserted

SQL> commit;
Commit complete

 

SQL> SELECT * FROM DEPT;
DEPTNO DNAME          LOC
------ -------------- -------------
    31 CODE                  BJ
    10 ACCOUNTING     NEW YORK
    20 RESEARCH       DALLAS
    30 SALES          CHICAGO1
    40 OPERATIONS     BOSTON
    11 CODE           BEIJING
6 rows selected

 

 

结论:通过database link ,序列 向远程库中插入数据时,要使用远程库中的序列。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值