分类: Oracle
2008-11-18 14:18:29
在9i、
在rename的过程中,数据库自动维护约束完整性、索引和授权相关信息,从旧的对象到新的对象。
oracle会让所有依赖于重命名的对象失效,比如视图、同义词、存储过程、函数等等。这当然是比较容易理解的了,当它变更了名称,其依赖于它的对象就找不到原对象,所以只能是处于invalid状态。
需要注意的是:
1、 不能进行rename的回滚。
2、 对象必须在你的schema中。
Example:
SQL> conn cbo/cbo
Connected.
SQL> create sequence test_seq
2 start with 1
3 maxvalue 10000
4 minvalue 1
5 nocycle
6 cache 10
7 increment by 1;
Sequence created.
SQL> rename test_seq to seq;
Table renamed.
SQL> select test_seq.nextval from dual;
select test_seq.nextval from dual
*
ERROR at line 1:
ORA-02289: sequence does not exist
SQL> select seq.nextval from dual;
NEXTVAL
----------
1
SQL> create table t1(id number);
Table created.
SQL> create view t1_view as select * from t1;
View created.
SQL> rename t1_view to t1_view_new;
Table renamed.
SQL> select * from t1_view;
select * from t1_view
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> select * from t1_view_new;
no rows selected
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
T1_TABLESPACE TABLE
T1_VIEW_NEW VIEW
SQL> conn /as sysdba
Connected.
SQL> rename cbo.t1_tablespace to cbo.t1;
rename cbo.t1_tablespace to cbo.t1
*
ERROR at line 1:
ORA-01765: specifying table's owner name is not allowed
SQL> conn cbo/cbo
Connected.
SQL> rename t1_tablespace to t1;
Table renamed.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
T1 TABLE
T1_VIEW_NEW VIEW
SQL> rollback;
Rollback complete.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
T1 TABLE
T1_VIEW_NEW VIEW
SQL> exit
Disconnected from Oracle Database
With the Partitioning, OLAP, Data Mining and Real Application Testing options
细心一点我们可以发现不管是修改什么对象,数据库返回的结果都是table renamed。估计这是oracle的一个bug。在