简体   繁体   中英

Oracle SQL inserting a date into a table

INSERT INTO Booking(BOOKING_ID, TRIP_DETAILS, DATE_HIRE, DESTINATION, NO_OF_PASSENGERS)
VALUES ('01', 'Bus group', '17-07-18', 'Paradise', '4');

This is an example, say booking table exists and the date_hire is written as

Date_Hire date NOT NULL,

Is the date format incorrect? it tells me the month is not valid, so I went to tools, preference, nls and my date format is DD-MON-RR, so I did make an error the way I inserted it?

I strongly recommend using the DATE keyword with YYYY-MM-DD format:

INSERT INTO Booking (BOOKING_ID, TRIP_DETAILS, DATE_HIRE, DESTINATION, NO_OF_PASSENGERS)
    VALUES ('01', 'Bus group', DATE '2018-07-17', 'Paradise', 4);

Presumably, NO_OF_PASSENGERS is a number. Don't use single quotes for numbers. Only use single quotes for string and date constants.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM