Hello,
How can I get all the Days of the previous month in PL/SQL ?
Thanks.
Hello,
How can I get all the Days of the previous month in PL/SQL ?
Thanks.
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;
/
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))
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