如果说版本影响当前用户可以访问的对象是正常的,但是对于DBA_OBJECTS而言,同一个用户下,在不同版本下看到的结果也是不一样的。
看一个简单的例子:
-bash-3.2$ sqlplus test/test SQL*Plus: Release 11.2.0.2.0 Production ON Thu Sep 15 21:04:58 2011 Copyright (c) 1982, 2010, Oracle. ALL rights reserved. Connected TO: Oracle DATABASE 11g Enterprise Edition Release 11.2.0.2.0 - Production WITH the Partitioning, OLAP, DATA Mining AND REAL Application Testing options SQL> SET pages 100 LINES 120 SQL> CREATE USER u1 IDENTIFIED BY u1 DEFAULT tablespace users enable editions; USER created. SQL> GRANT CONNECT, resource, dba TO u1; GRANT succeeded. SQL> conn u1/u1 Connected. SQL> SELECT sys_context('USERENV', 'CURRENT_EDITION_NAME') FROM dual; SYS_CONTEXT('USERENV','CURRENT_EDITION_NAME') ------------------------------------------------------------------------ ORA$BASE SQL> CREATE OR REPLACE PROCEDURE p1 AS 2 BEGIN 3 NULL; 4 END; 5 / PROCEDURE created. SQL> CREATE OR REPLACE PROCEDURE p2 AS 2 BEGIN 3 NULL; 4 END; 5 / PROCEDURE created. SQL> CREATE OR REPLACE PROCEDURE p3 AS 2 BEGIN 3 NULL; 4 END; 5 / PROCEDURE created. SQL> CREATE edition e2; Edition created. SQL> SELECT COUNT(*) FROM dba_objects; COUNT(*) ---------- 13565 SQL> SELECT object_name, edition_name 2 FROM dba_objects 3 WHERE owner = USER 4 AND object_name LIKE 'P_'; OBJECT_NAME EDITION_NAME ------------------------------ ------------------------------ P3 ORA$BASE P2 ORA$BASE P1 ORA$BASE SQL> ALTER SESSION SET edition = e2; SESSION altered. SQL> SELECT COUNT(*) FROM dba_objects; COUNT(*) ---------- 13565 SQL> DROP PROCEDURE p2; PROCEDURE dropped. SQL> CREATE OR REPLACE PROCEDURE p1 AS 2 BEGIN 3 dbms_output.put_line('e2'); 4 END; 5 / PROCEDURE created. SQL> SELECT COUNT(*) FROM dba_objects; COUNT(*) ---------- 13564 SQL> SELECT object_name, edition_name 2 FROM dba_objects 3 WHERE owner = USER 4 AND object_name LIKE 'P_'; OBJECT_NAME EDITION_NAME ------------------------------ ------------------------------ P3 ORA$BASE P1 E2 SQL> CREATE OR REPLACE PROCEDURE p4 AS 2 BEGIN 3 NULL; 4 END; 5 / PROCEDURE created. SQL> SELECT COUNT(*) FROM dba_objects; COUNT(*) ---------- 13565 SQL> SELECT object_name, edition_name 2 FROM dba_objects 3 WHERE owner = USER 4 AND object_name LIKE 'P_'; OBJECT_NAME EDITION_NAME ------------------------------ ------------------------------ P3 ORA$BASE P4 E2 P1 E2 SQL> ALTER SESSION SET edition = ora$base; SESSION altered. SQL> SELECT COUNT(*) FROM dba_objects; COUNT(*) ---------- 13565 SQL> SELECT object_name, edition_name 2 FROM dba_objects 3 WHERE owner = USER 4 AND object_name LIKE 'P_'; OBJECT_NAME EDITION_NAME ------------------------------ ------------------------------ P3 ORA$BASE P2 ORA$BASE P1 ORA$BASE SQL> conn test/test Connected. SQL> SELECT COUNT(*) FROM dba_objects; COUNT(*) ---------- 13565 SQL> SELECT object_name, edition_name 2 FROM dba_objects 3 WHERE owner = 'U1' 4 AND object_name LIKE 'P_'; OBJECT_NAME EDITION_NAME ------------------------------ ------------------------------ P3 ORA$BASE P2 ORA$BASE P1 ORA$BASE |
可以看到,DBA_OBJECT视图是版本化的视图,即使是拥有DBA权限的用户在查询这个视图的时候也只能看到当前版本可见的视图,因此DBA_OBJECTS视图不在包括数据库中所有的对象,如果想要获取数据库中各个版本的所有对象,查询DBA_OBJECTS_AE视图:
SQL> SELECT object_name, edition_name 2 FROM dba_objects_ae 3 WHERE owner = 'U1' 4 AND object_name LIKE 'P_'; OBJECT_NAME EDITION_NAME ------------------------------ ------------------------------ P3 ORA$BASE P2 ORA$BASE P1 ORA$BASE P4 E2 P2 E2 P1 E2 6 ROWS selected. |