ORA-02069与database link ,synonym,sequence

    技术2022-05-20  37

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

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

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

     

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

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

     

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

    SQL> conn report/reportConnected 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用户登录创建序列DEPTIDSQL> conn scott/tigerConnected 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/reportConnected 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           BEIJING6 rows selected

     

     

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


    最新回复(0)