版本中删除对象导致当前和子版本中对象不可见

在文档中看到这部分的描述,不过有一个疑点不是很确认,于是验证了一下。

 

 

如果一个用户启用了版本,用户执行某个过程或函数时,如果在当前版本中找不到,自动会去父版本寻找,如果还找不到会去祖先版本中寻找,一直到ORA$BASE中都无法找到,才回报错对象不存在。

但是用户明确的删除操作会使得继承关系中断。一个用户如果删除当前版本中的对象,那么父版本中的对象并不会删除,只不过这个对象在当前版本中不在可见。

看到文档上的这个描述,我的疑问是,对于当前版本的子版本,能否判断父版本中对象是被删除,还是根本没有创建。换句话说,当前版本删除对象后,自版本能否绕过当前版本从父版本处继承对象。

-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 function f1 return varchar2 as
  2  begin
  3  return 'Edition ORA$BASE';
  4  end;
  5  /

Function created.

SQL> select f1 from dual;

F1
-----------------------------------------------------------------
Edition ORA$BASE

SQL> create function f2 return varchar2 as
  2  begin
  3  return 'Edition ORA$BASE';
  4  end;
  5  /

Function created.

SQL> select f2 from dual;

F2
------------------------------------------------------------------
Edition ORA$BASE

SQL> create edition e1;

Edition created.

SQL> alter session set edition = e1;

Session altered.

SQL> select f1 from dual;

F1
-------------------------------------------------------------------
Edition ORA$BASE

SQL> select f2 from dual;
F2
-------------------------------------------------------------------
Edition ORA$BASE

SQL> drop function f1;

Function dropped.

SQL> select f1 from dual;
select f1 from dual
       *
ERROR at line 1:
ORA-00904: "F1": invalid identifier

SQL> select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual;

SYS_CONTEXT('USERENV','CURRENT_EDITION_NAME')
----------------------------------------------------------------
E1

SQL> create edition e2 as child of e1;

Edition created.

SQL> alter session set edition = e2; 

Session altered.

SQL> select f1 from dual;
select f1 from dual
       *
ERROR at line 1:
ORA-00904: "F1": invalid identifier

SQL> select f2 from dual;

F2
-----------------------------------------------------------------------
Edition ORA$BASE

SQL> alter session set edition = ora$base;

Session altered.

SQL> select f1 from dual;

F1
-----------------------------------------------------------------------
Edition ORA$BASE

可以看到,在当前版本中删除对象后,父版本中对象仍然存在,但是继承关系中断,而当前版本的子版本也不可能再次继承该过程,当然版本中可以创建同名的对象,但是已经和父版本没有关系了。

 

请使用浏览器的分享功能分享到微信等