如果说版本影响当前用户可以访问的对象是正常的,但是对于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 wner = 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 wner = 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 wner = 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 wner = 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 wner = '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 wner = '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.