months_between

时间:2024-06-17 09:37:08

select months_between(to_date('2016.01.29','yyyy.mm.dd'), to_date('2016.02.29','yyyy.mm.dd'))  from dual

结果 1

select months_between(to_date('2016.02.29','yyyy.mm.dd'),to_date('2016.01.30','yyyy.mm.dd'))  from dual

结果 0.9677419354838709677419354838709677419355

select months_between(to_date('2016.02.29','yyyy.mm.dd'),to_date('2016.01.31','yyyy.mm.dd'))  from dual

结果 1

Mod是求余;
Ceil是取靠近值最大的整数;
floor是取靠近值最小的整数;
round是四舍五入;
select mod(10,3) from dual ---1
select mod(4.1,3.1) from dual ---1
select mod(4.9,3.1) from dual ---1.8
select ceil(10/3) from dual ---4
select ceil(3.1) from dual ---4
select floor(3.1) from dual ---3
select floor(3.9) from dual ---3
select round(3.5) from dual ---4
select round(3.1) from dual ---3

last_day(sysdate) --这个月最后一天

TRUNC (NUMBER)

语法:trunc (n1,n2)

返回n1截取到n2小数位,数据类型为NUMBER;若n2缺省则默认取整,数据类型同n1

TRUNC (DATE)

语法:trunc (date,fmt)

按fmt返回日期值,若fmt缺省则取到最近的日

TRUNC(sysdate,'mm')--当月第一天

相关文章