SELECT TO_CHAR(ADD_MONTHS(ADD_MONTHS(sysdate, -24), ROWNUM - 1), 'YYYYMM') UNIT_DATE FROM DUAL CONNECT BY ROWNUM <= months_between(sysdate, ADD_MONTHS(sysdate, -24))从Oracle替换成postgre
时间: 2023-05-26 21:05:13 浏览: 153
Oracle 中的 TO_DATE 和 TO_CHAR 函数
5星 · 资源好评率100%
SELECT to_char(date_trunc('MONTH',CURRENT_DATE - interval '2 year') + interval '1 month' * generate_series(0, date_part('year', age(CURRENT_DATE - interval '2 year')) * 12 + date_part('month', age(CURRENT_DATE - interval '2 year')) - 1), 'YYYYMM') AS UNIT_DATE FROM generate_series(0, date_part('year', age(CURRENT_DATE - interval '2 year')) * 12 + date_part('month', age(CURRENT_DATE - interval '2 year')) - 1) s;
阅读全文