SELECT ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM'), 1 * LEVEL - 1),
TRIM (
TO_CHAR (
ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM'),
1 * LEVEL - 1),
'Month'))
|| ' '
|| TO_CHAR (
ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM'),
1 * LEVEL - 1),
'YYYY')
Month
FROM DUAL
CONNECT BY LEVEL <= MONTHS_BETWEEN (SYSDATE, ADD_MONTHS (SYSDATE, -12)) + 1
ORDER BY ADD_MONTHS (TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM'), 1 * LEVEL - 1) desc
Sql query to return range of dates by month from number of months prior to current date.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.