本文介绍了甲骨文日期差获取年数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以计算日期之间的年数.不知道如何解决这一问题,而又没有考虑到这一点.是否可以在SELECT中执行IF语句?

Is there a way to calculate the number of years between dates. Not sure how to do this while accounting for leap and what not. Is it possible to do an IF statement maybe in the SELECT?

谢谢

推荐答案

我将使用months_between,可能与floor组合:

I'd use months_between, possibly combined with floor:

select floor(months_between(date '2012-10-10', date '2011-10-10') /12) from dual;

select floor(months_between(date '2012-10-9' , date '2011-10-10') /12) from dual;

floor确保您舍入了四舍五入的年份.如果需要小数部分,显然不要使用floor.

floor makes sure you get down-rounded years. If you want the fractional parts, you obviously want to not use floor.

这篇关于甲骨文日期差获取年数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:08