ORACLE有两方面的字符集,一是oracel server端的字符集,二是oracle client端的字符集。只有保证两个字符集一致,并且所选的字符集要能支持中文,才能不出乱码。
1.查询数据库当前字符集:
select userenv('language') from dual;
select * from V$NLS_PARAMETERS;
select * from nls_database_parameters;
select value from v$nls_parameters where PARAMETER = 'NLS_CHARACTERSET';
select userenv('language') from dual;
ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK;
可以重新在dbca中创建数据库并选择正确的字符集
2.查看Oracle客户端的字符集:
$ echo $NLS_LANG
设置客户端字符集
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.UTF8"可以解决中文字符乱码的问题。
在Windows下sqlplus完全正常,可是到Linux下,sqlplus中文显示就出问题了,总是显示“??”,这个问题又怎么解决呢?
经过在网络上查资料,以及尝试,得到的解法如下:
其实很简单我们只要设置退出sqlplus,设置相应的环境变量NLS_LANG
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.UTF8"
为了下次不必重新设置,我们可以将其放在/home/oracle/.bash_profile或/etc/profile中。重新进入sqlplus,但是发现原来在sqlplus中插入的数据中文还是显示"??",不过你重新插入一条看看,是不是可以正常显示中文了。
windows sqlplus客户端连接linux下Oracle修改为
export NLS_LANG="AMERICAN_AMERICA.UTF8"
3:
修改字符集WE8ISO8859成ZHS16GBK经过
[oracle@testdb2 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 5月 20 08:56:15 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218968 bytes
Variable Size 79693416 bytes
Database Buffers 197132288 bytes
Redo Buffers 7168000 bytes
Database mounted.
SQL> alter database noarchivelog;
Database altered.
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> 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 DATABAE CHARACTER SET SIMPLIFIED_CHINESE_CHINA.ZHS16GBK;
ALTER DATABAE CHARACTER SET SIMPLIFIED_CHINESE_CHINA.ZHS16GBK
*
ERROR at line 1:
ORA-00940: invalid ALTER command
SQL> ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK;
Database altered.
SQL> select * from nls_database_parameters;
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_LANGUAGE
AMERICAN
NLS_TERRITORY
AMERICA
NLS_CURRENCY
$
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_ISO_CURRENCY
AMERICA
NLS_NUMERIC_CHARACTERS
.,
NLS_CHARACTERSET
ZHS16GBK
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_CALENDAR
GREGORIAN
NLS_DATE_FORMAT
DD-MON-RR
NLS_DATE_LANGUAGE
AMERICAN
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_SORT
BINARY
NLS_TIME_FORMAT
HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT
DD-MON-RR HH.MI.SSXFF AM
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_TIME_TZ_FORMAT
HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT
DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY
$
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_COMP
BINARY
NLS_LENGTH_SEMANTICS
BYTE
NLS_NCHAR_CONV_EXCP
FALSE
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_NCHAR_CHARACTERSET
AL16UTF16
NLS_RDBMS_VERSION
10.2.0.1.0
20 rows selected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218968 bytes
Variable Size 79693416 bytes
Database Buffers 197132288 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
SQL> select * from nls_database_parameters;
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_LANGUAGE
AMERICAN
NLS_TERRITORY
AMERICA
NLS_CURRENCY
$
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_ISO_CURRENCY
AMERICA
NLS_NUMERIC_CHARACTERS
.,
NLS_CHARACTERSET
ZHS16GBK
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_CALENDAR
GREGORIAN
NLS_DATE_FORMAT
DD-MON-RR
NLS_DATE_LANGUAGE
AMERICAN
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_SORT
BINARY
NLS_TIME_FORMAT
HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT
DD-MON-RR HH.MI.SSXFF AM
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_TIME_TZ_FORMAT
HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT
DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY
$
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_COMP
BINARY
NLS_LENGTH_SEMANTICS
BYTE
NLS_NCHAR_CONV_EXCP
FALSE
PARAMETER
------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_NCHAR_CHARACTERSET
AL16UTF16
NLS_RDBMS_VERSION
10.2.0.1.0
20 rows selected.