https://www.cnblogs.com/plmm/p/7381496.html
1、用于截取年、月、日、时、分、秒
extract()函数
extract(year from sysdate) year ,extract(month from sysdate) month ,extract(day from sysdate) day
,extract (hour from sysdate) hour
,extract (minute from sysdate) minute
,extract (second from sysdate) second
to_char()函数
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual; //日期转化为字符串 select to_char(sysdate,'yyyy') as nowYear from dual; //获取时间的年 select to_char(sysdate,'mm') as nowMonth from dual; //获取时间的月 select to_char(sysdate,'dd') as nowDay from dual; //获取时间的日 select to_char(sysdate,'hh24') as nowHour from dual; //获取时间的时 select to_char(sysdate,'mi') as nowMinute from dual; //获取时间的分 select to_char(sysdate,'ss') as nowSecond from dual; //获取时间的秒
2、日期常用格式转换
to_char(sysdate,'YYYYMMDD W HH24:MI:SS'); //日期转成字符串
to_date('2004-05-07 13:23:44','yyyy-mm-dd hh24:mi:ss'); //字符串转成日期
TO_TIMESTAMP_TZ(to_char(SBSJ, 'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'); //日期类型 查询后时分秒不为零 to_date返回的 时分秒为零