字符乱码 导致 ORA-12899: value too large
问题场景:
1.创建测试表
create table t01(name varchar2(30))
2.插入数据
SQL> insert into t01 (name) values('所有分销商');
insert into t01 (name) values('所有分销商’)
*
ERROR at line 1:
ORA-12899: value too large for column "DRP"."T01"."NAME" (actual: 63, maximum:
30)
SQL>
问题分析:
猜测:可能是字符编码不一致,导致长度计算错误。
确认环境编码
1.终端CRT编码 UTF-8
2.数据库编码
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
---------------------------
AMERICAN_AMERICA.AL32UTF8
3.设置服务器变量
[oracle@Oracle02 ~]$ export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
再次测试:
SQL> insert into t01(name) values('中');
1 row created.
SQL> select * from t01;
NAME
------------------------------
中
SQL> insert into t01 (name) values('所有分销商');
1 row created.
SQL>
结论: NLS_LANG未设置导致字符编码不一致,导致长度计算错误。