ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 11gr2增强CREATE OR REPLACE TYPE功能

11gr2增强CREATE OR REPLACE TYPE功能

原创 Linux操作系统 作者:yangtingkun 时间:2012-07-06 23:43:47 0 删除 编辑

11.2对于CREATE OR REPLACE TYPE语句进行了增加,增加了FORCE选项。

 

 

在11.2之前,只要有其他的表或TYPE依赖了当前对象,这个对象就无法进行REPLACE了:

SQL> create type t_num_tab is table of number;
2 /

Type created.

SQL> create type t_record is object (id number, n_tab t_num_tab);
2 /

Type created.

SQL> create or replace type t_num_tab is table of number(5);
2 /
create or replace type t_num_tab is table of number(5);
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents

这是11.2之前的情况,尝试执行CREATE OR REPLACE将会导致ORA-2303错误,在11.2中Oracle增加了FORCE功能,使得一个仅被TYPE所依赖的对象仍然可以执行REPLACE的操作:

SQL> create or replace type t_num_tab force is table of number(5);
2 /

Type created.

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Solaris: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

有意思的是,FORCE语句的位置不对则不会生效,这时同样会报ORA-2303的错误,而并不会导致语句错误:

SQL> create or replace force type t_num_tab is table of number(5);
create or replace force type t_num_tab is table of number(5)
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents


SQL> create or replace type t_num_tab is table of number(5) force;
2 /
create or replace type t_num_tab is table of number(5) force;
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents

最后这个功能只对被TYPE所依赖的对象有效,一旦对象被表所依赖,则FORCE功能也不起作用:

SQL> create table t_type_tab (id number, c_tab t_num_tab)
2 nested table c_tab store as c_tab_tab;

Table created.

SQL> create or replace type t_num_tab force is table of number(6);
2 /
create or replace type t_num_tab force is table of number(6);
*
ERROR at line 1:
ORA-22866: cannot replace a type with table dependents

Oracle的错误信息也变成了ORA-22866。其实这时可以预料的,因为一旦创建了表,就相当于进行了实体化的工作,如果依赖的类型发生了变化,将会影响表中已有的数据的读写。不过其实Oracle可以做到更进一步,就是如果表段没有创建或者表中没有插入数据的情况下,允许对依赖的对象进行修改。

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4227/viewspace-735234/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2007-12-29

  • 博文量
    1964
  • 访问量
    11085795