错误:ORA-01861:文字与格式字符串不匹配

时间:2013-01-03 10:11:34

标签: oracle

有人可以在上述代码中找到错误:

INSERT INTO FMS_LOG (FL_ID,FL_USER_ID, FL_OFFICE_ID, FL_DATETIME,
                     FL_IP,FL_FISCAL_YEAR,FL_USER_NAME,FL_USER_ADDRESS) 
VALUES 
( 105, 18, 18, 
  TO_DATE('03/Jan/2013 15:51:33PM','DD/MON/YY HH:MI:SSAM'), 
 '127.0.0.1',
 '2069/70', 
 'dordhankuta', 
 'balaju' );

FL_DATETIME的字段类型为 DATE

这是抛出错误:

ORA-01861: literal does not match format string

服务器端代码:

    $this->db->query("
    INSERT INTO FMS_LOG (FL_ID,FL_USER_ID, FL_OFFICE_ID, FL_DATETIME, FL_IP,FL_FISCAL_YEAR,FL_USER_NAME,FL_USER_ADDRESS) 
    VALUES 
        (
        $next_id,
        $userinfo[user_id], 
        $userinfo[user_office_id],
        TO_DATE('".date('d/M/Y H:i:sA', time()+20700)."','DD/MON/YY HH:MI:SSAM'),
        '$client_ip',
        '$fiscal_year',
        '$userinfo[user_full_name]',
        '$address'
        )        
    ");

1 个答案:

答案 0 :(得分:2)

首先,15PM不存在。 其次,年份掩码应为yyyy,而不是yy

这有效:

select  TO_DATE('03/Jan/2013 15:51:33','DD/MON/YYYY HH24:MI:SS') from dual;

如果你想使用AM / PM,请确保小时在1到12之间,这可行:

select  TO_DATE('03/Jan/2013 5:51:33PM','DD/MON/YYYY HH:MI:SSAM') from dual;