https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions136.htm
ROUND(date [, fmt ])
Purpose
ROUND
returns date
rounded to the unit specified by the format model fmt
. The value returned is always of datatype DATE
, even if you specify a different datetime datatype for date
. If you omit fmt
, then date
is rounded to the nearest day. The date
expression must resolve to a DATE
value.
ROUND
返回date
四舍五入到 格式模型fmt 指定的单位。返回的值始终为数据类型DATE
,即使您指定的参数date为
不同的datetime数据类型。如果省略fmt
,则date
舍入到最近的一天。该date
表达式必须解析为一个DATE
值。
SELECT ROUND(TO_DATE( '27 -OCT-00', 'DD -MON -YY','NLS_DATE_LANGUAGE = American' ),'YEAR')from dual
分析一year
select round(to_date('1-0月-18'),'year') from dual;
select round(to_date('1-1月-18'),'year') from dual;
select round(to_date('1-5月-18'),'year') from dual;
select round(to_date('1-6月-18'),'year') from dual;
select round(to_date('1-7月-18'),'year') from dual;
select round(to_date('1-12月-18'),'year') from dual;
结论 一 1-6 年不进,7-12年进1
再执行一句
select to_char(round(to_date('1-1月-18'),'year'),'YYYY-MM-DD HH24:MI:SS') from dual;
可见 四舍五入到 年时 ,后面的时间都默认为 1月1日0分0秒 ,下面的测试类似
分析二month
select round(to_date('15-10月-18'),'month') from dual;
select round(to_date('16-10月-18'),'month') from dual;
总结二 1-15 月不进 ,16-30/31月进1
分析三day
select round(to_date('17-10月-18'),'day') from dual; --17-10月-18 周三 14-10月-18 周日
select round(to_date('18-10月-18'),'day') from dual; --18-10月-18 周四 21-10月-18 周日
总结三 天数按**周一至周三 和 周四至周日 **四舍五入到最近的 周日
ok