Orcal 里 date 转换的几种函数

Orcal 里 date 转换的几种函数

to_date():字符串转换成日期

  • orcal里不区分大小写
  • 月:mm 分钟:mi 小时(24小时制):hh24
select to_date('2020-12-04 10:18:18','yyyy-mm-dd hh24:mi:ss') from dual;

to_char(): 日期转字符串

select to_char(sysdate,'yyyy-mm-dd') from dual;

trunc(): 截取日期或数字

select trunc(sysdate) from dual;--返回当天日期 2020/12/04
select trunc(sysdate,'dd') from dual; --返回当天日期 2020/12/04
select trunc(sysdate,'mm') from dual; --返回当月第一天 2020/12/01
select trunc(sysdate,'yy') from dual; --返回当年第一天 2020/1/01
select trunc(sysdate,'yyyy') from dual; --返回当年第一天 2020/1/01
select trunc(sysdate,'d') from dual; --返回当周第一天(星期天) 2020/11/29
select trunc(sysdate,'hh') from dual; --返回当前小时 2020/12/04 10:00:00
select trunc(sysdate,'mi') from dual; --返回当前分钟 2020/12/04 10:42:00
  • 数字截取(不会四舍五入)
select trunc(123.456) from dual; --123
select trunc(123.456,0) from dual; --123
select trunc(123.456,1) from dual; --123.4
select trunc(123.456,-1) from dual; --120
posted @ 2020-12-04 10:47  阿灿呀  阅读(292)  评论(0)    收藏  举报