I am learning SQL and using Oracle SQL Developer. I have a table that contains the following columns
- FlightDate
- DepartureTime
- ArrivalTime
I have inserted values using either
TO_DATE('10:45', 'hh24:mi')
or
TO_DATE('20/10/2000', 'DD/MM/YYYY')
When I do a SELECT * FROM TABLE_NAME, the DepartureTime and ArrivalTime display a date (which I have not entered). How do I display the date in the first column and time in the other 2 columns?
I have tried `
SELECT to_char(DepartureTime, 'HH24:MI' ) AS Departure
to_char( ArrivalTime, 'HH24:MI' ) AS Arrival
FROM FLIGHT;
` Although the above statement displays the right values, I want to write a statement to output all the columns (because the actual table has more than 3 columns), but in the format explained above - a date for FlightDate and time for DepartureTime and ArrivalTime.
In Oracle, a
DATEis a binary data type that consists of 7 bytes representing century, year-of-century, month, day, hour, minute and second. It ALWAYS has all of those components and it is NEVER stored in any particular (human-readable) format.Therefore, if you have a
DATEit will always be both a date and a time.If you only want to store the date component of a date then you will need to use the entire date but could add a constraint to ensure the time is always midnight.
If you want to store a time without a date then you can either:
DATEdata type and just set the time component (and ignore the default values of the date component); orINTERVAL DAY TO SECONDdata type.For example, your table could be:
Or, you could simplify your table to:
and not worry about having separate dates and times.