SQL Server 从数据类型 varchar 转换为 numeric 时出错
1,起因2,执行语句INSERT INTO [dbo].[A_student]([name], [age], [score]) VALUES ('张三', 22, '');错误提示:3,原因因为浮点类型的数据字段无法插入空数据4,解决所以我在写后端拼接sql的时候,需要将语句修改为INSERT INTO [dbo].[A_student]([name], [age], [score]) VALUE
·
1,起因
2,执行语句
INSERT INTO [dbo].[A_student]([name], [age], [score]) VALUES ('张三', 22, '');
错误提示:
3,原因
因为浮点类型的数据字段无法插入空数据
4,解决
所以我在写后端拼接sql的时候,需要将语句修改为
INSERT INTO [dbo].[A_student]([name], [age], [score]) VALUES ('张三', 22, NULL);
执行成功
5,代码处理
参数值为空,将空变为null
//这里的paramlist是一个sql语句中需要传递给形参数值的list类型数据
paramlist.stream().forEach(
stringObjectMap -> {
for (String key : stringObjectMap.keySet()){
if (StringUtil.isEmptyOrLength0(stringObjectMap.get(key))){
stringObjectMap.put(key,null);
}
}
}
);
更多推荐
已为社区贡献3条内容
所有评论(0)