--linux Xshell下插入中文数据乱码
SQL> insert into test1 values(1,'张三','男',20);
-- Windows PLSQL下提示ORA-00942 “???...”
Select * From xxxx;
Oracle客户端(Sqlplus)通过NLS_LANG环境变量来确定客户端使用的字符集
NLS_LANG参数由以下部分组成:
NLS_LANG=_.
AMERICAN_AMERICA.AL32UTF8
AMERICAN_AMERICA.ZHS16GBK
AMERICAN_AMERICA.WE8MSWIN1252
--创建数据库安装部署配置
Select * From Nls_Database_Parameters
--客户端环境变量字符集配置
Select * From Nls_Session_Parameters
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.WE8MSWIN1252
SQL> alter system enable restricted session;
System altered.
SQL> ALTER DATABASE CHARACTER SET AL32UTF8;
ALTER DATABASE CHARACTER SET AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
--提示新字符集必须为旧字符集的超集,跳过超集的检查做更改
SQL> ALTER DATABASE character set INTERNAL_USE AL32UTF8;
ALTER DATABASE character set INTERNAL_USE AL32UTF8;
*
ERROR at line 1:
ORA-12721: operation cannot execute when other sessions are active
--当前有连接处于active状态,kill掉session或者重启数据库
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter system enable restricted session;
System altered.
SQL> alter database open;
Database altered.
SQL> ALTER DATABASE character set INTERNAL_USE AL32UTF8;
Database altered.
SQL> alter system disable restricted session;
System altered.
SQL> select userenv('language') from dual;
##### # 关闭受限模式
```powershell
SQL> alter system disable restricted session;
System altered.
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
--创建数据库安装部署配置
Select * From Nls_Database_Parameters
--客户端环境变量字符集配置
Select * From Nls_Session_Parameters
# 创建表
SQL> create table test1(ID number PRIMARY KEY,NAME varchar2(10) ,SEX varchar2(10),AGE number);
# 插入表测试数据
SQL> insert into test1 values ('3','小一','男','30');
# 查询表数据
SQL> select * from test1;