我正在使用Oracle SQL Developer工具编写Oracle插入语句,因此:
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 + "'); "
答案 0 :(得分:1)
MI格式意味着分钟..希望你得到它作为月和我。我把它放在这里作为例如10。
与格式中的AM相同,表示上午或下午。
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 + "'); "