2019-07-25 记录一个bug,插入更新sql-ON DUPLICATE KEY UPDATE
作者:互联网
以前没写过ON DUPLICATE KEY UPDATE,写了一个插入更新,写错了,把ON DUPLICATE KEY UPDATE写在for循环里,也没写values,不知道为啥之前没测试出来,赶紧记录一下
错误:
<foreach collection="list" index="index" item="item" separator=",">
( #{item.groupNum},#{item.organizeId}, #{item.taxTime}, #{item.periodTax}, #{item.invoicePeriodTax},
#{item.purchaseTaxDeduction}, #{item.taxDeductionForPurchaseTax}, #{item.vatDeclaration}, #{item.purchaseTaxCurrentAmount},
#{item.gmtCreate}, #{item.gmtModified} )
ON DUPLICATE KEY UPDATE period_tax = #{item.periodTax}, invoice_period_tax = #{item.invoicePeriodTax},
purchase_tax_deduction = #{item.purchaseTaxDeduction}, tax_deduction_for_purchase_tax = #{item.taxDeductionForPurchaseTax},
vat_declaration = #{item.vatDeclaration},
purchase_tax_current_amount = #{item.purchaseTaxCurrentAmount};
</foreach>
错误点:第一,不应该写在for循环里,第二没写values,第三等于后是写表字段
正确:
<foreach collection="list" index="index" item="item" separator=",">
( #{item.groupNum},#{item.organizeId}, #{item.taxTime}, #{item.periodTax}, #{item.invoicePeriodTax},
#{item.purchaseTaxDeduction}, #{item.taxDeductionForPurchaseTax}, #{item.vatDeclaration}, #{item.purchaseTaxCurrentAmount},
#{item.gmtCreate}, #{item.gmtModified} )
</foreach>
ON DUPLICATE KEY UPDATE
period_tax = VALUES (period_tax), invoice_period_tax = VALUES (invoice_period_tax),
purchase_tax_deduction = VALUES (purchase_tax_deduction), tax_deduction_for_purchase_tax = VALUES (tax_deduction_for_purchase_tax),
vat_declaration = VALUES (vat_declaration),
purchase_tax_current_amount = VALUES (purchase_tax_current_amount);
period_tax = VALUES (period_tax),
这种格式的,参考:https://www.cnblogs.com/zjdxr-up/p/8319982.html
标签:25,07,purchase,tax,UPDATE,period,deduction,item,VALUES 来源: https://blog.csdn.net/hq091117/article/details/97264916