当前位置:   article > 正文

mysql:Incorrect datetime value: ‘‘

incorrect datetime value:

最近在做调度时,需要生成中间表数据,使用sql如下:

  1. -- 脚本1
  2. INSERT INTO ct_zr_pay_paid_overdue_payment_record ( created_time)
  3. SELECT now()
  4. FROM (business_contract bc, fund_channel fc, acct_loan al, acct_payment_schedule aps)
  5. LEFT JOIN plan_payment_way ppw ON aps.serialno = ppw.serialno
  6. WHERE bc.fundno = fc.fundno
  7. AND bc.serialno = al.serialno
  8. AND bc.serialno = aps.objectno
  9. AND bc.orgId = 'EDU2017071000000002'
  10. AND date_format('20200211', '%Y%m') = date_format(aps.finishdate, '%Y%m')
  11. AND aps.finishdate < date_format('20200211', '%Y/%m/%d')
  12. -- 脚本2
  13. INSERT INTO ct_zr_pay_paid_overdue_payment_record ( created_time)
  14. SELECT now()
  15. FROM (business_contract bc, fund_channel fc, acct_loan al, acct_payment_schedule aps)
  16. LEFT JOIN plan_payment_way ppw ON aps.serialno = ppw.serialno
  17. WHERE bc.fundno = fc.fundno
  18. AND bc.serialno = al.serialno
  19. AND bc.serialno = aps.objectno
  20. AND bc.orgId = ''
  21. AND date_format('20200211', '%Y%m') = date_format(aps.finishdate, '%Y%m')
  22. AND aps.finishdate < date_format('20200211', '%Y/%m/%d')

 

 在执行时两个脚本查询出的数据都是0条,但是脚本1报错,脚本2不报错,脚本1报错:Incorrect datetime value: '',经过排查,可以通过两个方法避免报错问题,但生产上还是需要用方法二

  1. -- 方法一
  2. -- 允许无效格式日期时间
  3. -- 详细说明见stackOverFlow:
  4. --https://stackoverflow.com/questions/22806870/incorrect-datetime-value-database-error-number-1292
  5. SET SESSION SQL_MODE='ALLOW_INVALID_DATES'
  6. -- 方法二
  7. -- 在查询后在union all一个空值即可
  8. INSERT INTO ct_zr_pay_paid_overdue_payment_record ( created_time)
  9. SELECT now()
  10. FROM (business_contract bc, fund_channel fc, acct_loan al, acct_payment_schedule aps)
  11. LEFT JOIN plan_payment_way ppw ON aps.serialno = ppw.serialno
  12. WHERE bc.fundno = fc.fundno
  13. AND bc.serialno = al.serialno
  14. AND bc.serialno = aps.objectno
  15. AND bc.orgId = 'EDU2017071000000002'
  16. AND date_format('20200211', '%Y%m') = date_format(aps.finishdate, '%Y%m')
  17. AND aps.finishdate < date_format('20200211', '%Y/%m/%d')
  18. union all
  19. select now() from ct_zr_pay_paid_overdue_payment_record where 1=2

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/607112
推荐阅读
相关标签
  

闽ICP备14008679号