Bigdecial类型的坑

在处理资金时常用到bigdecial类型。但是需要注意踩坑。

1.如果使用mybatis操作数据库时,你的sql如下:

money原来位1.23

update table set money=money-0.1 where id=1;

那么money肯不是1.13,而是1.1,丢失精度。可使用做下转换:

cast(#{money} as numeric(15,2))

2.如果使用mybatis操作数据库时,你的sql如下:

insert into (money) values (#{money})

如果money值为null时是会报错的。此时应该在mybatis插入时做下判断

 Unable to translate SQLException with Error code '515', will now try the fallback translator

你可能感兴趣的:(mybatis,数据库,mysql)