背景
select @@version;
# @@version
'5.7.41-log'
select @@sql_mode;
# @@sql_mode
'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
举例
drop table test2;
create table test2 (
id1 decimal(1,1),
id2 decimal(2,1)
);
insert into test2 values(0,'你好');
Error Code: 1366. Incorrect decimal value: '你好' for column 'id2' at row 1
insert into test2 values(0,cast('你好'as decimal(2,1)));
Error Code: 1292. Truncated incorrect DECIMAL value: '你好'
insert into test2 values(0,cast(replace('你好','好','')as decimal(2,1)));
Error Code: 1366. Incorrect DECIMAL value: '0' for column '' at row -1
insert into test2 values(0,111);
Error Code: 1264. Out of range value for column 'id2' at row 1
insert into test2 values(0,cast('1.1' as decimal(2,1)));
1 row(s) affected
insert into test2 values(0,convert('1.011', decimal(2,1)));
1 row(s) affected
说明
Decimal 默认最大位数(精度,precision)是 10 ,默认小数点位数(scale)是 0 。
最大位数(精度,precision) M 范围为 1 到 65 ,小数点位数(scale) D 范围为 0 到 30 ,整数位数为(M - D),小数点位数为 D 。
Decimal 使用 二进制格式存储。
————————————————
中文、字母、符号无法转换成定点数
步骤:定位错误,修改错误...