您的位置:首页 > 数据库 > Oracle

修改ORACLE字符集

2011-05-18 13:09 253 查看
字符集实质就是按照一定的字符编码方案,对一组特定的符号,分别赋予不同数值编码的集合。Oracle数据库最早支持的编码方案是US7ASCII。
Oracle的字符集命名遵循以下命名规则:
<Language><bit size><encoding>
即: <语言><比特位数><编码>
比如: ZHS16GBK表示采用GBK编码格式、16位(两个字节)简体中文字符集。下面用简单的方法修改ORACLE数据库字符集。

原来数据库字符集是US7ASCII:

SQL> select * from nls_database_parameters;

PARAMETER VALUE

-------------------------------- --------------------------------
...

NLS_CHARACTERSET US7ASCII
...

20 rows selected.

修改字符集为AL32UTF8。

关闭数据库:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

启动到Mount:
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1073741824 bytes
Fixed Size 1223540 bytes
Variable Size 310379660 bytes
Database Buffers 754974720 bytes
Redo Buffers 7163904 bytes
Database mounted.

SQL> alter system enable restricted session;

System altered.

SQL> alter system set job_queue_processes=0;

System altered.

SQL> alter system set aq_tm_processes=0;

System altered.

SQL> alter database open;

Database altered.

现在可以修改字符集:

SQL> alter database character set AL32UTF8;
alter database character set AL32UTF8
*
ERROR at line 1:
ORA-12716: Cannot ALTER DATABASE CHARACTER SET when CLOB data exists

存在CLOB字段,不能更改字符集,对于clob字符集可以考虑用其他方法进行转换,这里使用INTERNAL_USE 参数,跳过超子集检测:

SQL> alter database character set internal_use al32utf8;

Database altered.

转换完毕后重启数据库:

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 1073741824 bytes
Fixed Size 1223540 bytes
Variable Size 318768268 bytes
Database Buffers 746586112 bytes
Redo Buffers 7163904 bytes
Database mounted.
Database opened.

检查数据库字符集,已经转换成功:

SQL> select * from nls_database_parameters;

PARAMETER VALUE
-------------------------------- --------------------------------
...
NLS_CHARACTERSET AL32UTF8
...

20 rows selected.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: