|
|
|
|
Re: month and month number [message #289979 is a reply to message #289971] |
Thu, 27 December 2007 00:26 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
There are variations to the subject; all of them end up with the row generator techniques. Here are two of them; explore the rest by yourself.
SELECT
TO_CHAR(ADD_MONTHS(TRUNC(SYSDATE, 'yyyy'), LEVEL - 1), 'month') mon_1,
TO_CHAR(ADD_MONTHS(TRUNC(SYSDATE, 'yyyy'), LEVEL - 1), 'mm') mon_2
FROM dual
CONNECT BY LEVEL <= 12
ORDER BY 2;
WITH YEAR AS
(SELECT ADD_MONTHS(TRUNC(SYSDATE, 'yyyy'), LEVEL - 1) mon
FROM dual
CONNECT BY LEVEL <= 12
)
SELECT TO_CHAR(mon, 'month') mon_1,
TO_CHAR(mon, 'mm') mon_2
FROM YEAR
ORDER BY 2;
|
|
|