oracle months_between week,ORACLE MONTHS_BETWEEN函数使用

因系统折旧月份是按当月是否满15天来算是否为一个月,故此研究了下MONTHS_BETWEEN已适应折旧的逻辑

官网函数说明:

MONTHS_BETWEEN官网说明

MONTHS_BETWEEN returns number of months between dates date1 and date2. If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise Oracle Database calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2.

MONTHS_BETWEEN返回日期date1和date2之间的月数。如果date1晚于date2,则结果为正数。如果date1早于date2,则结果为负。如果date1和date2是一个月的相同天数或两个月的最后几天,那么结果总是一个整数。否则,Oracle数据库将根据一个31天的月份计算结果的小数部分,并考虑date1和date2时间组件的差异。

examples:

`SELECT MONTHS_BETWEEN (TO_DATE("02-02-2020","MM-DD-YYYY"), TO_DATE("01-01-2020","MM-DD-YYYY") ) "Months" FROM DUAL;

Months

1.03225806`

months_between算法为01-01-2020到02-02-2020,2020年一月份算一个整月,不整的为2月份的两天,

于是 MONTHS_BETWEEN (TO_DATE(“02-02-2020″,”MM-DD-YYYY”),TO_DATE(“01-01-2020″,”MM-DD-YYYY”) ) = 1+2/31=1.03225806

一般也就是months_between的两个参数月需要计算小数部分,最多为开始月算小数+中间月+结束月算xiao”shu;最少为不算,直接为整数月

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值