相信很多人都会遇到安装oracle后字符集编码不一致而导致的各种问题,现在讲下如何修改字符集格式。
一、查询字符集
1、查询oracle server端 字符集
select userenv('language') from dual
其中NLS_CHARACTERSET 为server端字符集
NLS_LANGUAGE 为 server端字符显示形式
2、查询oracle client端 字符集
Linux:
$echo $NLS_LANG
如果发现你select 出来的数据是乱码,请把client端的字符集配置成与linux操作系统相同的字符集。如果还是有乱码,则有可能是数据库中的数据存在问题,或者是oracle服务端的配置存在问题。
Windows:
cmd下输入命令:chcp
默认为936,中国 - 简体中文(GB2312)
二、server端字符集修改
更改字符集步骤方法(WE8ISO8859P1 --> ZHS16GBK)
开始 - 运行 - 输入cmd 进入命令提示符
输入 sqlplus /nolog
以管理员身份登录sqlplus:
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 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
System altered.
查询连接参数设置并记下参数值:
SQL> show parameter job_queue_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes integer 10
SQL> show parameter aq_tm_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
aq_tm_processes integer 1
暂时将连接数改为0防止任务自动执行(确保无连接可省略):
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 DATABASE character set INTERNAL_USE ZHS16GBK;
Database altered.
SQL> select * from v$nls_parameters;
略
19 rows selected.
关闭数据库并切换到挂载模式,还原连接参数设置并打开数据库(之前未修改参数可省略):
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL> alter system set job_queue_processes=10;
System altered.
SQL> alter system set aq_tm_processes=1;
System altered.
SQL> alter database open;
Database altered.
重启检查是否更改完成:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> select * from v$nls_parameters;
略
19 rows selected.
三、添加环境变量修改client端字符集
设置oracle用户的的环境
linux下修改环境变量(临时)
export NLS_LANG="SIMPLIFIED Chinese_CHINA.ZHS16GBK"
Windows下修改环境变量
如果是windows,按照以下方法添加或者修改,在系统变量中添加如下信息:
变量名:NLS_LANG
变量值:SIMPLIFIED Chinese_CHINA.ZHS16GBK
再进行查询,字符集是不是已经更改过来了呢。
标签:ZHS16GBK,Database,字符集,bytes,System,SQL,oracle From: https://www.cnblogs.com/surplus/p/18179704