我在甲骨文11.2是2014年12月30日。查询
select to_char(sysdate ,'YYYYIW') from dual返回201401而不是201501
我错了还是甲骨文?
发布于 2014-12-30 12:10:32
如果您想要ISO年以及ISO周,请使用IYYY格式模型
select to_char(sysdate,'IYYYIW') from dual;
TO_CHAR(SYSDATE,'IYYYIW')
-------------------------
201501 混合ISO和非ISO会给你带来奇怪的结果。您可以看到这样做的不同之处:
with t as (
select date '2014-12-19' + level as dt
from dual connect by level <= 18
)
select to_char(t.dt, 'YYYY-MM-DD') as dt,
to_char(t.dt, 'YYYYWW') as normal,
to_char(t.dt, 'YYYYIW') as iso_week,
to_char(t.dt, 'IYYYIW') as iso
from t
order by t.dt;
DT NORMAL ISO_WEEK ISO
---------- ------ -------- ------
2014-12-20 201451 201451 201451
2014-12-21 201451 201451 201451
2014-12-22 201451 201452 201452
2014-12-23 201451 201452 201452
2014-12-24 201452 201452 201452
2014-12-25 201452 201452 201452
2014-12-26 201452 201452 201452
2014-12-27 201452 201452 201452
2014-12-28 201452 201452 201452
2014-12-29 201452 201401 201501
2014-12-30 201452 201401 201501
2014-12-31 201453 201401 201501
2015-01-01 201501 201501 201501
2015-01-02 201501 201501 201501
2015-01-03 201501 201501 201501
2015-01-04 201501 201501 201501
2015-01-05 201501 201502 201502
2015-01-06 201501 201502 201502 发布于 2014-12-30 12:00:23
这不是甲骨文的小毛病。
YYYY以四位的成绩返回这一年,而不考虑接下来或之前的情况。因为sysdate在2014年,所以2014返回201401是正确的。
https://stackoverflow.com/questions/27705050
复制相似问题