开发者

Days of last month inPL/SQL

开发者 https://www.devze.com 2023-01-05 10:31 出处:网络
How can I get all the Days of the previous开发者_运维问答 month in PL/SQL ? Thanks.SELECTLAST_DAY(ADD_MONTHS(SYSDATE, -2)) + level

How can I get all the Days of the previous开发者_运维问答 month in PL/SQL ?

Thanks.


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))


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;
/


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号