用简单的方法实现Oracle测试库更改用户名

一般修改用户名大多使用导出用户a再导入用户b来实现用户名的换名。假如在测试库上你可以用下面的方法来简单实现,这样就不用导出了。

注释:重要的生产库不建议这样做。

conn / as sysdba
UPDATE USER$ SET NAME='A2B' WHERE NAME='HH';
ALTER SYSTEM CHECKPOINT;--强制写入数据文件
ALTER SYSTEM FLUSH SHARED_POOL;--清除缓存数据字典信息
alter user a2b identified by a;

SQL> conn hh/a
Connected.

SQL> SELECT COUNT(*) FROM USER_OBJECTS;

COUNT(*)
----------
952
SQL> conn / as sysdba
Connected.
SQL> show user
USER is "SYS"

SQL> UPDATE USER$ SET NAME='A2B' WHERE NAME='HH';

1 row updated.

SQL> commit;

Commit complete.

SQL> ALTER SYSTEM CHECKPOINT;

System altered.

SQL> ALTER SYSTEM FLUSH SHARED_POOL;

System altered.

SQL> alter user a2b identified by a;

User altered.

SQL> conn a2b/a
Connected.
SQL> SELECT COUNT(*) FROM USER_OBJECTS;

COUNT(*)
----------
952

SQL>