为什么下面的sql会产生ORA-01810错误?我研究了错误,我为每个日期插入使用不同的日期格式
INSERT INTO bag_grte_clm ( schd_dprt_ldt, arr_trpn_stn_cd, bkg_crtn_gdt, sbmt_bag_grte_clm_dt, bag_grte_clm_stt_cd, lst_updt_gts, bag_grte_clm_gts, dprt_trpn_stn_cd ) VALUES ( TO_DATE('2015/12/06', 'yyyy/mm/dd'), 'YUL', TO_DATE('2015-11-15', 'yyyy-mm-dd'), TO_DATE('120615', 'MMDDYY'), 'DENIAL', (current_timestamp), TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss'), 'ATL' )
Lalit Kumar .. 47
TO_TIMESTAMP('20151206 00:00:00','yyyymmdd hh:mm:ss')
这有两个方面是错误的:
1.格式代码不正确
您重复了MM
两次格式掩码.MM
是月份,MI
是分钟.
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss') FROM dual; SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss') FROM dual * ERROR at line 1: ORA-01810: format code appears twice
2.时间部分不正确
00:00:00
是错误的,因为它会抛出ORA-01849,因为小时不能为零,它必须在1到12之间.
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mi:ss') FROM dual; SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mi:ss') FROM dual * ERROR at line 1: ORA-01849: hour must be between 1 and 12
正确的方法是使用24小时格式,或保留默认的时间部分12 AM
.
例如,
24小时格式:
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh24:mi:ss') my_tmstamp FROM dual; MY_TMSTAMP --------------------------------------------------------------------------- 06-DEC-15 12.00.00.000000000 AM
没有时间部分:
SQL> SELECT TO_TIMESTAMP('20151206', 'yyyymmdd') my_tmstamp FROM dual; MY_TMSTAMP ----------------------------------------------------------------------- 06-DEC-15 12.00.00.000000000 AM
Mr. Llama.. 12
您已经使用了mm
两次格式代码TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss')
MM
是月份
MI
是分钟
你可能意味着使用YYYYMMDD HH:MI:SS
.
有关更多信息,请参阅日期格式模型列表.
TO_TIMESTAMP('20151206 00:00:00','yyyymmdd hh:mm:ss')
这有两个方面是错误的:
1.格式代码不正确
您重复了MM
两次格式掩码.MM
是月份,MI
是分钟.
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss') FROM dual; SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss') FROM dual * ERROR at line 1: ORA-01810: format code appears twice
2.时间部分不正确
00:00:00
是错误的,因为它会抛出ORA-01849,因为小时不能为零,它必须在1到12之间.
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mi:ss') FROM dual; SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mi:ss') FROM dual * ERROR at line 1: ORA-01849: hour must be between 1 and 12
正确的方法是使用24小时格式,或保留默认的时间部分12 AM
.
例如,
24小时格式:
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh24:mi:ss') my_tmstamp FROM dual; MY_TMSTAMP --------------------------------------------------------------------------- 06-DEC-15 12.00.00.000000000 AM
没有时间部分:
SQL> SELECT TO_TIMESTAMP('20151206', 'yyyymmdd') my_tmstamp FROM dual; MY_TMSTAMP ----------------------------------------------------------------------- 06-DEC-15 12.00.00.000000000 AM
您已经使用了mm
两次格式代码TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh:mm:ss')
MM
是月份
MI
是分钟
你可能意味着使用YYYYMMDD HH:MI:SS
.
有关更多信息,请参阅日期格式模型列表.