DoveyDovel
DoveyDovel

Reputation: 83

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?

Upvotes: 0

Views: 42

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270993

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.

Upvotes: 2

Related Questions