首页 技术 正文
技术 2022年11月15日
0 收藏 972 点赞 3,955 浏览 3202 个字

本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn

[转自]http://www.xifenfei.com/2012/08/oracle%e7%94%a8%e6%88%b7%e9%87%8d%e5%91%bd%e5%90%8d.html

从oracle 11.2.0.2开始提供了用户重命名的新特性,在以前的版本中,如果想对用户重命名,一般来说是先创建一个新的用户并授权,然后将原用户下的所有对象导入,然后删除旧的用户!

数据库版本信息

SQL> select* from v$version;BANNER
--------------------------------------------------------------------------------
Oracle Database11g Enterprise Edition Release 11.2.0.3. - Production
PL/SQL Release 11.2.0.3. - Production
CORE11.2.0.3.0 Production
TNS forLinux: Version 11.2.0.3. - Production
NLSRTL Version 11.2.0.3. - Production

创建测试环境

SQL> create user xifenfei identified by xifenfei;User created.SQL> grant connect,resource to xifenfei;Grant succeeded.SQL> conn xifenfei/xifenfei
Connected.SQL> create table t_xifenfei as select* from user_users;Table created.SQL> create index ind_t_xifenfei on t_xifenfei(user_id);Index created.SQL> conn / assysdba
Connected.
SQL> select object_type,object_name from dba_objects where owner='XIFENFEI';OBJECT_TYPE OBJECT_NAME
------------------- ---------------------------------------------------------
TABLE T_XIFENFEI
INDEX IND_T_XIFENFEI

尝试修改用户名

SQL> alter user xifenfei rename to xff identified by xifenfei;
alter user xifenfei rename to xff identified by xifenfei
*
ERROR atline :
ORA-: missing orinvalid option--默认值是false
SQL> col name for a32
SQL> col value for a24
SQL> col description for a70
SQL> set linesize
SQL> select a.ksppinm name,b.ksppstvl value,a.ksppdesc description
from x$ksppi a,x$ksppcv b
where a.inst_id = USERENV ('Instance')
and b.inst_id = USERENV ('Instance')
and a.indx = b.indx
and upper(a.ksppinm) LIKE upper('%&param%')
order by name
/
Enter value forparam: _enable_rename_user
old :andupper(a.ksppinm) LIKEupper('%&param%')
new :andupper(a.ksppinm) LIKEupper('%_enable_rename_user%')NAME VALUEDESCRIPTION
-------------------------------- ------------------------ ------------------------------------------------
_enable_rename_user FALSEenable RENAME-clause using ALTERUSERstatementSQL> startup force restrict
ORACLE instance started.Total System GlobalArea bytes
Fixed Size bytes
Variable Size bytes
Database Buffers bytes
Redo Buffers6516736 bytes
Database mounted.
Database opened.--_enable_rename_user=false,在restrict模式也不能修改用户名
SQL> ALTER user XFF RENAME TO xffei IDENTIFIED BY xifenfei;
ALTER user XFF RENAME TO xffei IDENTIFIED BY xifenfei
*
ERROR atline :
ORA-: missing orinvalid option

设置隐含参数

SQL> alter system set "_enable_rename_user"=true scope=spfile;System altered.SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.SQL> startup restrict
ORACLE instance started.Total System GlobalArea bytes
Fixed Size bytes
Variable Size bytes
Database Buffers bytes
Redo Buffers6516736 bytes
Database mounted.
Database opened.
SQL> ALTER user xifenfei RENAME TO xff IDENTIFIED BY xifenfei;Useraltered.

测试结果

SQL> startup force
ORACLE instance started.Total System GlobalArea bytes
Fixed Size bytes
Variable Size bytes
Database Buffers bytes
Redo Buffers6516736 bytes
Database mounted.
Database opened.
SQL> select object_type,object_name from dba_objects where owner='XIFENFEI';no rows selectedSQL> select object_type,object_name from dba_objects where owner='XFF';OBJECT_TYPE OBJECT_NAME
------------------- ----------------------------------------------------
TABLE T_XIFENFEI
INDEX IND_T_XIFENFEISQL> conn xff/xifenfei
Connected.
SQL> select count(*) from t_xifenfei; COUNT(*)
----------

相关文档和上面的测试,得出结论:数据库版本在11.2.0.2及其以上版本,_enable_rename_user设置为true,数据库启动到restrict模式可以修改用户名

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903