2015-12-28 106 views
1

當我嘗試運行此語句時,Oracle不斷收到此錯誤。我不確定格式錯誤來自哪裏。也許有人用新鮮的眼睛可以幫助我解決這個問題。SQL錯誤:ORA-01861:文字不匹配格式字符串

INSERT INTO Faculty 
(FacNo, FacFirstName, FacLastName, FacCity, FacState, 
FacDept, FacRank, FacSalary, FacSupervisor, FacHireDate, FacZipCode) 
VALUES ('543-21-0987','VICTORIA','EMMANUEL','BOTHELL','WA','MS','PROF',120000.0,'','2001-04-15','98011-2242'); 

以下是錯誤消息我不斷收到:

Error starting at line : 1 in command - 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.

下面是桌子上的規格我試圖此數據插入到:最有可能

FACNO CHAR(11 BYTE)
FACFIRSTNAME VARCHAR2(30 BYTE)
FACLASTNAME VARCHAR2(30 BYTE)
FACCITY VARCHAR2(30 BYTE)
FACSTATE CHAR(2 BYTE)
FACZIPCODE CHAR(10 BYTE)
FACRANK CHAR(4 BYTE)
FACHIREDATE DATE
FACSALARY NUMBER(10,2)
FACSUPERVISOR CHAR(11 BYTE)
FACDEPT CHAR(6 BYTE)

+1

也許這個鏈接將幫助:http://stackoverflow.com/questions/22542882/sql-error-ora-01861-literal-does-not-match-format-string-01861 –

+0

使用'to_date()'與格式掩碼或ANSI日期文字:'date'2001-04-15''。詳細信息在手冊中:https://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements003.htm#SQLRF51062 –

+0

to_date('2001-04-15','yyyy-mm-dd') –

回答

2

,你NLS_DATE_FORMAT,文字的默認日期格式與您的字符串不匹配。永遠不要假設日期格式是這樣或那樣。使用TO_DATE功能來指定格式,所以轉換爲:

Insert (... to_date('2001-04-15','YYYY-MM-DD') ...

+0

這工作。謝謝。 @OldProgrammer –

0

OldProgrammers的答案是正確的答案。顯式地將字符串轉換爲日期是最安全的。 MS-SQL通常會自動轉換任何可識別的日期,如果您的格式與系統的默認格式匹配,Oracle會執行此操作。我所使用的所有oracle系統都使用「DD/MON/YY」或兩位數字日期,三個字母月份縮寫和兩位數年份作爲默認值,並自動將其轉換。不是正確的做法,但每個人都喜歡有時懶惰。