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 tbable 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 tb 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可以做到更進一步,就是如果表段沒有創建或者表中沒有插入數據的情況下,允許對依賴的對象進行修改。