SQL数据截断:日期值不正确

时间:2015-11-08 04:40:20

标签: sql error-handling oracle11g truncation

我收到此错误。

  

数据截断:日期值不正确:列的'18 -JUN-13'   第1行的'dateFrom'

出现此错误的原因是什么?

INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('01', '01', '18-JUN-13', '26-NOV-13', '01'); 
INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('02', '01', '18-JUN-85', '26-JUN-85', '02'); 
INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('02', '03', '18-JUN-66', '26-JUN-66', '01'); 
INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('04', '02', '18-OCT-13', '23-OCT-13', '01'); 
INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('02', '03', '18-JUL-87', '26-AUG-87', '01'); 
INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('02', '03', '18-AUG-87', '26-AUG-87', '01'); 
INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('02', '01', '18-AUG-87', '26-SEP-87', '01');

1 个答案:

答案 0 :(得分:2)

如果您不一定非常需要依赖格式化日期use the SQL standard DATE literal instead, as I've described in this blog post,请始终。所以,而不是:

array_multisort

...写道:

INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) 
VALUES ('01', '01', '18-JUN-13', '26-NOV-13', '01'); 

如果需要该格式(例如,因为您正在从某些外部源加载数据),请使用INSERT INTO Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) VALUES ('01', '01', DATE '2013-06-18', DATE '2013-11-26', '01'); 来解析它:

TO_DATE()