时间:2021-07-01 10:21:17 帮助过:17人阅读
最近安装个Oracle 10g数据库,dbca建库的时候没选字符集或者选错的情况,导入数据后,中文全部是乱码(搞笑的是,中文乱码 居然全
最近安装个Oracle 10g数据库,dbca建库的时候没选字符集或者选错的情况,导入数据后,中文全部是乱码(搞笑的是,中文乱码 居然全部是个“靠”字),查看网络几篇文章,也做了相应修改(以前按方法修改可以解决的,今天特例!),解决办法如下:
SQL> connect / as sysdba; ---dba用户连接数据库
SQL> select name,value$ from props$ where name like '%NLS%';---语句查询当前数据库服务器字符集
NAME
------------------------------------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_LANGUAGE
AMERICAN
NLS_TERRITORY
AMERICA
NLS_CURRENCY
$
NAME
------------------------------------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_ISO_CURRENCY
AMERICA
NLS_NUMERIC_CHARACTERS
.,
NLS_CHARACTERSET ----找到查出来的结果中的该项参数
WE8ISO8859P1
下面是修改过程:
SQL> shutdown immediate; ---停止数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount ---启动数据库到mount状态
ORACLE instance started.
Total System Global Area 235999352 bytes
Fixed Size 450680 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
---下面是修改过程,按步骤修改
SQL> alter session set sql_trace=true;
Session altered.
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> set linesize 120;
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;
# 使用INTERNAL_USE可以跳过超集的检查,
(ALTER DATABASE character set INTERNAL_USE )
Database altered.
SQL> shutdown immediate; ---再停止数据库
Database closed.
Database dismounted.
ORACLE instance shut down.
---启动数据库
SQL> STARTUP
ORACLE instance started.
Total System Global Area 235999352 bytes
Fixed Size 450680 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL>
----再次查看当前字符集
SQL> select name,value$ from props$ where name like '%NLS%';
NAME
------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_LANGUAGE
SIMPLIFIED CHINESE
NLS_TERRITORY
CHINA
NLS_CURRENCY
?
NAME
------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_ISO_CURRENCY
CHINA
NLS_NUMERIC_CHARACTERS
.,
NLS_CHARACTERSET
ZHS16GBK ---【已经修改成为中文编码了】
今天的情况特殊,修改完了,中文乱码还是“靠”字,- -
后来试着修改系统字符集
在oracle下 .bash_profile 文件里面加入
export NLS_LANG="Simplified Chinese_CHINA.ZHS16GBK"
再次登录查看,还是不行
最后把NLS_LANG中后面的字符集ZHS16GBK修改成AL32UTF8,查看结果,搞掂完成,回家!
总结:要系统字符集和数据库字符集相对应才会解决中文乱码问题,dbca建库时,,也要注意字符集选择问题。