Reputation: 55
I have a column DT, which contains dates in a format like this: 01-FEB-22 and etc
How can I write sql script, which would display the dates like shown in DT_n column:
DT | DT_N |
---|---|
01-FEB-22 | 22 FEB |
01-JAN-22 | 22 JAN |
01-DEC-21 | 21 DEC |
Also, I need to order DT_n in chronological order, latest month and year should be the last.
I have next SQL script for the last 12 months:
SELECT ADD_MONTHS(TRUNC(SYSDATE,'MM'),
1-(LEVEL)) AS DT,
LAST_DAY(ADD_MONTHS(TRUNC(SYSDATE,'MM'), 1-(LEVEL))) AS DT_LAST_DAY
FROM DUAL
CONNECT BY LEVEL <= 12
Upvotes: 0
Views: 46
Reputation: 37472
Just use to_char()
.
SELECT dt,
to_char(dt, 'YY MON') dt_n
FROM elbat;
Upvotes: 3