查看数据库当前字符集
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.WE8MSWIN1252
将数据库置于restricted mode下
SQL> alter system enable restricted session;
System altered.
置于restricted mode是为了防止数据库有新的非dba权限的连接,关于restricted mode请查看我的blog [http://blog.csdn.net/dbdoctor/article/details/51907531]
修改字符集到ZHS16GBK
SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改:
SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
ALTER DATABASE character set INTERNAL_USE ZHS16GBK
*
ERROR at line 1:
ORA-12721: operation cannot execute when other sessions are active
当前有连接处于active状态,kill掉session或者重启数据库。
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 922747784 bytes
Database Buffers 3338665984 bytes
Redo Buffers 12107776 bytes
Database mounted.
SQL> alter system enable restricted session;
System altered.
SQL> alter database open;
Database altered.
SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
Database altered.
SQL> alter system disable restricted session;
System altered.
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK