Oracle obtains the year, month, day, hour, minute, and second in the data table

Recently, I am using the oracle database to select data, because I have been using mysql before, I always encounter some problems, and record it.

For example, if the time is taken out, the format in the database is "year-month-day hour: minute: second", but after it is taken out, it is in the format "01-SEP-20". So you have to adjust the sql statement.
The sql statement can refer to the following:

--获取年
select to_char(sysdate,'yyyy') from dual--2016
select to_char(sysdate,'YYYY') from dual--2016
--获取月
select to_char(sysdate,'mm') from dual--10
select to_char(sysdate,'MM') from dual--10
--获取日
select to_char(sysdate,'dd') from dual--10
select to_char(sysdate,'DD') from dual--10
--获取时
select to_char(sysdate,'hh24') from dual--15
select to_char(sysdate,'hh') from dual--03
select to_char(sysdate,'HH') from dual--03
select to_char(sysdate,'HH24') from dual--15
--获取分钟
select to_char(sysdate,'MI') from dual--14
select to_char(sysdate,'mi') from dual--14
--获取秒
select to_char(sysdate,'ss') from dual--35
select to_char(sysdate,'SS') from dual--40
--获取年月日时分秒
select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual--2016-10-10 03:17:25
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual--2016-10-10 15:17:51

(1) From the above test SQL, it can be seen that the case of year, month, day yyyy, mm, dd, hh, mi, ss has no effect on obtaining year, month, day, hour, minute and second from Oracle
(2) For obtaining hour, minute, 12 hours and In the 24-hour situation, if you want to get the time displayed in the afternoon, you can use hh24, which will display something like 15:30 instead of 03:30

Reference from: https://blog.csdn.net/u012934325/article/details/52778136/

Guess you like

Origin blog.csdn.net/z3287852/article/details/111401860