PL / SQL上个月的日子

时间:2010-06-28 13:34:04

标签: sql oracle select date-arithmetic

如何在PL / SQL中获取上个月的所有日期?

感谢。

3 个答案:

答案 0 :(得分:4)

SELECT  LAST_DAY(ADD_MONTHS(SYSDATE, -2)) + level
FROM    dual
CONNECT BY
        level <= LAST_DAY(ADD_MONTHS(SYSDATE, -1)) - LAST_DAY(ADD_MONTHS(SYSDATE, -2))

答案 1 :(得分:1)

喜欢这个吗?

begin
for i in 1..to_char(trunc(sysdate,'mm')-1,'dd') loop
    dbms_output.put_line(i);
end loop;
end;
/

或者如果你想要约会:

begin
for i in 1..to_char(trunc(sysdate,'mm')-1,'dd') loop
    dbms_output.put_line(i+trunc(trunc(sysdate,'mm')-1,'mm')-1);
end loop;
end;
/

答案 2 :(得分:0)

试试这个

WITH d AS
(
SELECT TRUNC ( sysdate, 'MM' ) - 1 AS dt
FROM dual
)
SELECT dt + LEVEL
FROM d
CONNECT BY LEVEL <= ADD_MONTHS (dt, 1) - dt