2014-11-24 81 views
0

請我需要在Oracle INSERT語句一些幫助,我用Oracle SQL Developer tool ,這是插入語句錯誤的日期時間與甲骨文插入語句

INSERT INTO ITEMAPPROVAL (REQUESTITEMID, USERID, APPROVALSTATUS, REQUESTSTATUSID, ITEMAPPROVALDATE, ITEMAPPROVALNOTE , APPROVEDAMOUNT) 
       VALUES ('132568', '15', '1', '4', TO_DATE('06/02/1436:10:6i:41a6', 'mm/dd/yyyy:hh:mi:ssam'), '' ,'20000'); 

上運行總是我有以下錯誤

Error starting at line : 23 in command - 
INSERT INTO ITEMAPPROVAL (REQUESTITEMID, USERID, APPROVALSTATUS, REQUESTSTATUSID, ITEMAPPROVALDATE, ITEMAPPROVALNOTE , APPROVEDAMOUNT) 
       VALUES ('132568', '15', '1', '4', TO_DATE('06/02/1436:10:6i:41am', 'mm/dd/yyyy:hh:mi:ssam'), '' ,'20000') 

    Error report - 
     SQL Error: ORA-01861: literal does not match format string 
     01861. 00000 - "literal does not match format string" 
     *Cause: Literals in the input must be the same length as literals in 
        the format string (with the exception of leading whitespace). If the 
        "FX" modifier has been toggled on, the literal must match exactly, 
        with no extra whitespace. 
     *Action: Correct the format string to match the literal. 

我認爲錯誤屬於日期格式,我多搜索了一下,但沒有任何希望

更新:

格式從Visual Studio生成像

query = "INSERT INTO ITEMAPPROVAL " + 
           "   (REQUESTITEMID, USERID, APPROVALSTATUS, REQUESTSTATUSID, ITEMAPPROVALDATE, ITEMAPPROVALNOTE , APPROVEDAMOUNT) " + 
           " VALUES ('" + itemapproval.RequestItemID + "', '" + itemapproval.User.ID + "', '" + itemapproval.status + "', '" + itemapproval.requeststatus.ID + "', TO_DATE('" + itemapproval.date.ToString("mm/dd/yyyy:hh:mi:ssam") + "', 'mm/dd/yyyy:hh:mi:ssam'), '" + itemapproval.notes + "' ,'" + itemapproval.ApprovedAmount + "'); " 
+1

ERM TO_DATE('06/02/1436:10:6I:41a6' – 2014-11-24 07:38:42

+0

您的日期輸入??什麼是6I – 2014-11-24 07:38:49

+0

感謝米奇和Maheswaran快速回復,我得到了這個日期從點網轉換就像我寫的嗎?在問題更新 – 2014-11-24 07:43:15

回答

1

MI查詢手段分鐘..希望你得到它爲一個月和我。我以10爲例。

與AM格式相同意味着am或pm。

INSERT INTO ITEMAPPROVAL (REQUESTITEMID, USERID, APPROVALSTATUS, REQUESTSTATUSID, ITEMAPPROVALDATE, ITEMAPPROVALNOTE , APPROVEDAMOUNT) 
       VALUES ('132568', '15', '1', '4', TO_DATE('06/02/1436:10:10:41am', 'mm/dd/yyyy:hh:mi:ssam'), '' ,'20000'); 

嘗試在.NET

mm/dd/yyyy:hh:mm:ss.tt 

以下格式的字符串,並將其會是什麼樣子,

query = "INSERT INTO ITEMAPPROVAL " + 
           "   (REQUESTITEMID, USERID, APPROVALSTATUS, REQUESTSTATUSID, ITEMAPPROVALDATE, ITEMAPPROVALNOTE , APPROVEDAMOUNT) " + 
           " VALUES ('" + itemapproval.RequestItemID + "', '" + itemapproval.User.ID + "', '" + itemapproval.status + "', '" + itemapproval.requeststatus.ID + "', TO_DATE('" + itemapproval.date.ToString("mm/dd/yyyy:hh:mi:ssam") + "', 'mm/dd/yyyy:hh:mm:sstt'), '" + itemapproval.notes + "' ,'" + itemapproval.ApprovedAmount + "'); " 

NET reference on Date formats

+0

你的意思是我改變 itemapproval.date.ToString(「mm/dd/yyyy:hh:mi:ssam」) to itemapproval.date.ToString(「MM/dd/yyyy: hh:mm:ss tt「) – 2014-11-24 07:49:51

+0

@AbrahamJosef是的! – 2014-11-24 07:56:39