Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38883
  • 博文数量: 11
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 70
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-25 14:44
文章分类
文章存档

2015年(11)

我的朋友

分类: Oracle

2015-10-31 09:27:35

本文转载处:

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

点击(此处)折叠或打开

  1. SQL> create type t_num_tab istableof number;
  2.     
  3.     2 /
  4.     
  5.     Type created.
  6.     
  7.     SQL> create type t_record is object (id number, n_tab t_num_tab);
  8.     
  9.     2 /
  10.     
  11.     Type created.
  12.     
  13.     SQL> create or replace type t_num_tab is table of number(5);
  14.     
  15.     2 /
  16.     
  17.     create or replace type t_num_tab is table of number(5);
  18.     
  19.     *
  20.     
  21.     ERROR at line 1:
  22.     
  23.     ORA-02303: cannot drop or replace a type with type or table dependents
这是11.2之前的情况,尝试执行CREATE OR REPLACE将会导致ORA-2303错误,在11.2中增加了FORCE功能,使得一个仅被TYPE所依赖的对象仍然可以执行REPLACE的操作:

点击(此处)折叠或打开

  1. SQL> create or replace type t_num_tab force istbable of number(5);
  2. 2 /

  3. Type created.

  4. SQL> select * from v$version;

  5. BANNER

  6. --------------------------------------------------------------------------------

  7. Oracle Database11gEnterprise Edition Release 11.2.0.3.0 - 64bit Production

  8. PL/SQL Release 11.2.0.3.0 - Production

  9. CORE 11.2.0.3.0 Production

  10. TNS for Solaris: Version 11.2.0.3.0 - Production

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

点击(此处)折叠或打开

  1. SQL> create or replace force type t_num_tab is table of number(5);
  2.     
  3.     create or replace force type t_num_tab is table of number(5)
  4.     
  5.     *
  6.     
  7.     ERROR at line 1:
  8.     
  9.     ORA-02303: cannot drop or replace a type with type or table dependents
  10.     
  11.     SQL> create or replace type t_num_tab is table of number(5) force;
  12.     
  13.     2 /
  14.     
  15.     create or replace type t_num_tab is table of number(5) force;
  16.     
  17.     *
  18.     
  19.     ERROR at line 1:
  20.     
  21.     ORA-02303: cannot drop or replace a type with type or table dependents
最后这个功能只对被TYPE所依赖的对象有效,一旦对象被表所依赖,则FORCE功能也不起作用:

点击(此处)折叠或打开

  1. SQL> create table t_type_tab (id number, c_tab t_num_tab)
  2.     
  3.     2 nested table c_tab storetbas c_tab_tab;
  4.     
  5.     Table created.
  6.     
  7.     SQL> create or replace type t_num_tab force is table of number(6);
  8.     
  9.     2 /
  10.     
  11.     create or replace type t_num_tab force is table of number(6);
  12.     
  13.     *
  14.     
  15.     ERROR at line 1:
  16.     
  17.     ORA-22866: cannot replace a type with table dependents

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

阅读(2610) | 评论(0) | 转发(0) |
0

上一篇:Oracle入门命令

下一篇:没有了

给主人留下些什么吧!~~