在Oracle下客户端中设置的字符集应于服务端保持一致,否则会出现乱码,而Oracle的客户端无论是在Windows/DOS系统下还是Unix系统下都可以通过环境变量NLS_LANG来加以控制,至于操作也很简单,在这里就不做过多的说明,在这里主要说一下如何在Oracle的服务端下如何正确的修改字符集。在修改的时候建议使用sysdba身份验证,要注意的是新修改的字符集必须为旧字符集的超集,不然Oracle上修改字符集会报ORA-12712错误。而在平时可以查询系统视图得知当前Oracle数据库中的字符集设置情况,如下:
SELECT * FROM v$nls_parameters WHERE PARAMETER IN ('NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET'); #通过NLS_LANGUAGE,NLS_TERRITORY,NLS_CHARACTERSET这三个变量查看
SELECT USERENV ('language') FROM DUAL;#或者通过USERENV函数也可以取得
操作方法也很简单:
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 905970568 bytes
Database Buffers 3355443200 bytes
Redo Buffers 12107776 bytes
Database mounted.
SQL> alter system enable restricted session;#在维护模式的基础上再开启restricted,防止其他用户登录连接
System altered.
SQL> alter system set job_queue_processes=0;#关闭系统的触发器
System altered.
SQL> alter system set aq_tm_processes=0;#指定队列监视进程个数,缺省是0,如果没有改过可以不加
System altered.
SQL> alter database open;#打开数据库
Database altered.
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 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 905970568 bytes
Database Buffers 3355443200 bytes
Redo Buffers 12107776 bytes
Database mounted.
Database opened.