此处以20180612为例子
想得到上年末、上年同期、上月末这些时间点,只需要记住函数ADD_MONTHS、LAST_DAY、ADD_YEARS这些函数即可。
上年末
SELECT SUBSTR(TO_CHAR(ADD_YEARS(TO_DATE('20180612','YYYYMMDD'),-1) ,'YYYYMMDD'),1,4)||'1231' FROM SYSIBM.DUAL;
上月末
SELECT TO_CHAR(LAST_DAY(ADD_MONTHS(TO_DATE('20180612','YYYYMMDD'),-1)) ,'YYYYMMDD')FROM SYSIBM.DUAL;
上年同期
或者