oracle字符集查看修改

一、 查看字符集

1. 查看DB Server字符集

select * from nls_database_parameters where parameter in ('NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET','NLS_NCHAR_CHARACTERSET');

2. 查看客户端字符集

可以看到基本都是通过操作系统命令在查,原因是 only the client knows their character set as well — it is not available “in the database”

#On UNIX:
SQL> HOST ECHO $NLS_LANG

#On Windows(环境变量设置)
SQL> HOST ECHO %NLS_LANG%
#On Windows(注册表设置)
SQL> @.[%NLS_LANG%].

#或者(只能查到字符集,没有国家和区域信息)
SELECT * FROM NLS_SESSION_PARAMETERS;

二、 修改字符集

1. 修改DB Server字符集

shutdown immediate;

startup mount;
--限制session
alter system enable restricted session;
--查询相关参数并修改(防止有任务自动启动执行,一般不做也没关系)
show parameter job_queue_processes; -- 记下这个值
show parameter aq_tm_processes; -- 记下这个值
alter system set job_queue_processes=0;
alter system set aq_tm_processes=0;
Alter database open;

-- 按需修改nls_characterset,其中INTERNAL_USE表示跳过字符集检查
alter database character set internal_use AL32UTF8;
-- 按需修改nls_nchar_characterset
ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE UTF8;
-- 查看修改后字符集
select * from nls_database_parameters;

shutdown immediate;
startup mount;
--将相关参数改回原来的值
alter system set job_queue_processes=xxx;
alter system set aq_tm_processes=xxx;
Alter database open;

2. 修改客户端字符集(NLS_LANG)

关于NLS_LANG参数的解释:

NLS_LANG = NLS_LANGUAGE_NLS_TERRITORY.NLS_CHARACTERSET

eg: export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
    export NLS_LANG=AMERICAN_AMERICA.UTF8
    export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
  • NLS_LANGUAGE:指定服务器消息的语言, 影响提示信息是中文还是英文
  • NLS_TERRITORY:指定服务器的日期和数字格式
  • NLS_CHARACTERSET:指定字符集。

Windows与Linux通用改法

ALTER SESSION SET NLS_LANGUAGE=AMERICAN; -- 视服务器端字符集设置情况修改

Windows改法

当前会话生效

进入cmd
set NLS_LANG=SIMPLIFIED CHINESE_CHINA.AL32UTF8
set NLS_LANG=AMERICAN_AMERICA.AL32UTF8

永久生效

将windows环境变量NLS_LANG值设置为SIMPLIFIED CHINESE_CHINA.AL32UTF8

Unix/Linux改法

查看方法

su - oracle
env | grep NLS_LANG

修改方法

使用export命令设置该环境变量,或直接加进~/.bash_profile里

export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"

参考

NLS_LANG Explained (How does Client-Server Character Conversion Work?) (文档 ID 158577.1)

[转载]Oracle Character set – Everything a New oracle DBA needs to know – FangwenYu – 博客园

Determine Oracle session client character set? – Database Administrators Stack Exchange

    原文作者:Hehuyi_In
    原文地址: https://blog.csdn.net/Hehuyi_In/article/details/89493969
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞