Oracle 11gR2 用户重命名(rename user)
Posted 太白的技术博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle 11gR2 用户重命名(rename user)相关的知识,希望对你有一定的参考价值。
Oracle 11.2.0.2里新增了一个新特性——用户重命名(Rename User),在这个版本之前要想重命名用户,需要按用户导出,再fromuser touser(imp)或remap_schem(impdp)。还可以通过修改数据字典user$的方式来重命名用户,但这种方法可能会带来风险。有了这个特性之后,可以通过alter user oldname rename to newname identified by "password";一条命令来重命名用户。
下面来看测试过程,使用Oracle版本11.2.0.4
[email protected]>select * from v$version;
BANNER
-------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
1、创建测试用户及测试表
[email protected]>create user sq identified by "sq";
User created.
[email protected]>grant connect,resource to sq;
Grant succeeded
[email protected]>create table sq.t1 as select * from dba_tables;
Table created.
2、执行alter user语句
[email protected]>alter user sq rename to zlx identified by "zlx";
alter user sq rename to zlx identified by "zlx"
*
ERROR at line 1:
ORA-00922: missing or invalid option
报错无效的操作,原来是需要修改隐含参数"_enable_rename_user"
3、修改隐含参数"_enable_rename_user",并以restrict模式重启数据库
[email protected]>alter system set "_enable_rename_user"=true scope=spfile;
System altered.
[email protected]>startup restrict force;
ORACLE instance started.
Total System Global Area 1620115456 bytes
Fixed Size 2253704 bytes
Variable Size 956304504 bytes
Database Buffers 654311424 bytes
Redo Buffers 7245824 bytes
Database mounted.
Database opened.
4、再次执行alter user语句,重命名用户
[email protected]>alter user sq rename to zlx identified by "zlx";
User altered.
[email protected]>select count(*) from sq.t1;
select count(*) from sq.t1
*
ERROR at line 1:
ORA-00942: table or view does not exist
[email protected]>select count(*) from zlx.t1;
COUNT(*)
----------
2864
[email protected]>conn zlx/zlx
ERROR:
ORA-01035: ORACLE only available to users with RESTRICTED SESSION privilege
Warning: You are no longer connected to ORACLE.
[email protected]>conn / as sysdba
Connected.
[email protected]>alter system disable restricted session;
System altered.
[email protected]>conn zlx/zlx
Connected.
[email protected]>select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------------------ --------------------- ----------
T1 TABLE
从上面的结果来看用户名重命名成功。
5、reset隐含参数"_enable_rename_user"并重启数据库
[email protected]>alter system reset "_enable_rename_user";
System altered.
以上是关于Oracle 11gR2 用户重命名(rename user)的主要内容,如果未能解决你的问题,请参考以下文章
苹果Mac强大的批量重命名工具:A Better Finder Rename