gpt4 book ai didi

SQL 数据截断 : Incorrect date value

转载 作者:行者123 更新时间:2023-12-03 07:50:00 26 4
gpt4 key购买 nike

我遇到了这个错误。

Data truncation: Incorrect date value: '18-JUN-13' for column 'dateFrom' at row 1

这个错误可能是什么原因?

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');

最佳答案

如果您不是绝对需要依赖格式化日期,use the SQL standard DATE literal instead, as I've described in this blog post , 总是。所以,而不是:

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() 来解析它:

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

关于SQL 数据截断 : Incorrect date value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33590810/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com