[20191021]改名與namespace.txt

lfree發表於2019-10-21

[20191021]改名與namespace.txt

--//偶爾會給一些物件改名,會遇到一些容易引起歧義的地方,實際上由於namespace引起的.
--//透過例子說明:

1.環境:
SCOTT@test01p> @ ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.2.0.1.0     Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production              0

create sequence seq1;
create view vdept as select * from dept;

2.改名測試:
SCOTT@test01p> rename seq1 to seq2;
Table renamed.

SCOTT@test01p> rename vdept to v_dept;
Table renamed.

--//我修改sequence以及view,而成功後提示是"Table renamed.",而實際上oracle這些物件在相同的namespace空間中.
--//也許你可以認為oracle處理這些問題簡單化了.

SYS@test> select distinct kglhdnsp,kglhdnsd,kglobtyd from x$kglob order by 1;
KGLHDNSP KGLHDNSD                       KGLOBTYD
-------- ------------------------------ -----------------------------
    -119 OPTIMIZER EXPRESSION HEADER    Optimizer Expression Header
       0 SQL AREA                       CURSOR
       1 TABLE/PROCEDURE                CURSOR
       1 TABLE/PROCEDURE                FUNCTION
       1 TABLE/PROCEDURE                LIBRARY
       1 TABLE/PROCEDURE                OPERATOR
       1 TABLE/PROCEDURE                PACKAGE
       1 TABLE/PROCEDURE                PROCEDURE
       1 TABLE/PROCEDURE                SEQUENCE
       1 TABLE/PROCEDURE                SYNONYM
       1 TABLE/PROCEDURE                TABLE
       1 TABLE/PROCEDURE                TYPE
       1 TABLE/PROCEDURE                VIEW
       2 BODY                           CURSOR
       2 BODY                           PACKAGE BODY
       2 BODY                           TYPE BODY
       3 TRIGGER                        CURSOR
       3 TRIGGER                        TRIGGER
       4 INDEX                          INDEX
       5 CLUSTER                        CLUSTER
       5 CLUSTER                        CURSOR
      10 QUEUE                          QUEUE
      18 PUB SUB INTERNAL INFORMATION   PUB SUB INTERNAL INFORMATION
      23 RULESET                        RULESET
      45 MULTI-VERSION OBJECT FOR TABLE MULTI-VERSIONED OBJECT
      48 MULTI-VERSION OBJECT FOR INDEX MULTI-VERSIONED OBJECT
      51 SCHEDULER GLOBAL ATTRIBUTE     CURSOR
      51 SCHEDULER GLOBAL ATTRIBUTE     SCHEDULER GLOBAL ATTRIBUTE
      64 EDITION                        EDITION
      69 DBLINK                         CURSOR
      73 SCHEMA                         NONE
      74 DBINSTANCE                     CURSOR
      75 SQL AREA STATS                 CURSOR STATS
      82 SQL AREA BUILD                 CURSOR
      93 AUDIT POLICY                   AUDIT POLICY
     103 OPTIMIZER FINDING              Optimizer Finding
     104 OPTIMIZER DIRECTIVE OWNER      CURSOR
     104 OPTIMIZER DIRECTIVE OWNER      Optimizer Directive Owner
38 rows selected.

--//可以發現CURSOR, FUNCTION, LIBRARY, OPERATOR, PACKAGE, PROCEDURE, SEQUENCE, SYNONYM, TABLE, TYPE, VIEW在相同的名字空間.
--//也就是這些物件不允許重名.

SCOTT@test01p> rename seq2 to v_dept;
rename seq2 to v_dept
               *
ERROR at line 1:
ORA-00955: name is already used by an existing object

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2660882/,如需轉載,請註明出處,否則將追究法律責任。

相關文章