2010-06-28 67 views

回答

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

是否這樣?

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