报错现场还原
一个批量入库的sql本人测试的时候失常,在线上报了
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: ORA-01790: 表达式必须具备与对应表达式雷同的数据类型
原来的sql是这样写的
<insert id="batchInsert"> insert into <include refid="TABLE_NAME"/> ( CID, TS, PHONE, NUM_PACKAGE, COST_MONTHPRICE, COST_PRICE, ONLINE_TIME, LOG_TIME ) <foreach collection="list" item="item" separator="union all"> select #{item.cid}, #{item.ts}, #{item.phone}, #{item.numPackage}, #{item.costMonthprice}, #{item.costPrice}, #{item.onlineTime}, sysdate from dual </foreach> </insert>
其中onlineTime
字段在现场有空的状况,狐疑未加jdbcType=DATE的状况下mybatis将这个字段置为了''空串。
<insert id="batchInsert"> insert into <include refid="TABLE_NAME"/> ( CID, TS, PHONE, NUM_PACKAGE, COST_MONTHPRICE, COST_PRICE, ONLINE_TIME, LOG_TIME ) <foreach collection="list" item="item" separator="union all"> select #{item.cid,jdbcType=INTEGER}, #{item.ts,jdbcType=INTEGER}, #{item.phone,jdbcType=VARCHAR}, #{item.numPackage,jdbcType=VARCHAR}, #{item.costMonthprice,jdbcType=VARCHAR}, #{item.costPrice,jdbcType=VARCHAR}, #{item.onlineTime,jdbcType=DATE}, sysdate from dual </foreach> </insert>
我记得这个jdbcType有时还会引发索引生效的问题,所以当前还是都带上这个配置吧。