简体   繁体   中英

How can i register hours on Oracle's SQL Developer 20.2 for 11g database?

I'm trying to register a DATE and and hour field on a table. DATE is there, but i can't find the TIME type for the hour field. Is there another way to make the thing? Or am i missing something? I'm trying to register the hour on a '11:30' format.

An Oracle date column always contains a day and a time. There would generally be no reason to have a separate column to store the time.

create table foo (
  my_date_col date
);

insert into foo( my_date_col ) 
  values( to_date( '2020-11-23 11:30', 'yyyy-mm-dd hh24:mi' ) );

select trunc( my_date_col ) date_data_type_at_midnight,
       to_char( my_date_col, 'yyyy-mm-dd' ) string_representation_of_day,
       to_char( my_date_col, 'hh24:mi:ss' ) string_representation_of_time
  from foo;

There is no time datatype in Oracle. There is a date datatype, that stores the date and time .

You did not explain your actual use case, but: most of the times, you don't need, and don't want, to store the date and times in two separate columns. You can use date , that stores both. Then you can use date functions to access the date and time parts separately if you really need to (or use computed columns).

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