简体   繁体   中英

When to use the ROUND function in oracle

I want to store a time value in a table using the Date date format in oracle.
I also want to store it to the nearest hour using the round function. eg 1700, 1800
When exactly do I use the round function to do this? When defining the table type? or when creating the table? Or when using the INSERT command?

Do it on the insert:

INSERT INTO your_table (date_col) VALUES (ROUND(SYSDATE,'HH'));

You can use any arbitrary date value, I used SYSDATE for simplicity.

Use round(<datetime>, 'HH') . Example:

select round( to_date('2012-01-01 12:30','yyyy-mm-dd hh24:mi')
            , 'HH')
from dual

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