views:

55

answers:

3

Hello,

How can I get all the Days of the previous month in PL/SQL ?

Thanks.

+1  A: 

Like this ?

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

Or if you want date :

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;
/
N. Gasparotto
+4  A: 
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))
Quassnoi
A: 

Try this one

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
Bharat