Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

how to get the substring from the column value

HI Experts,

how to get the substring from the below query

SELECT ADD_MONTHS(TRUNC (LAST_DAY (SYSDATE)), -2)+1 start_date FROM DUAL
//01-AUG-18
expected o/p: AUG-18
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Hi srikotesh,

In Oracle, the easiest way to format a date string is with the TO_CHAR function.

SELECT TO_CHAR(ADD_MONTHS(TRUNC (LAST_DAY (SYSDATE)), -2)+1, 'MMM-DD') start_date FROM DUAL
I guess you need year:
SELECT to_char(ADD_MONTHS(TRUNC (LAST_DAY (SYSDATE)), -2)+1, 'MON-YY') start_date FROM DUAL

not day
SELECT TO_CHAR(ADD_MONTHS(TRUNC (LAST_DAY (SYSDATE)), -2)+1, 'MON-DD') start_date FROM DUAL

Apologies....
SOLUTION
Avatar of awking00
awking00
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of srikotesh
srikotesh

ASKER

how to give alias name to this query


SELECT to_char(ADD_MONTHS(TRUNC (LAST_DAY (SYSDATE)), -2)+1, 'MON-YY') start_date FROM DUAL

SELECT to_char(ADD_MONTHS(TRUNC (LAST_DAY (SYSDATE)), -2)+1, 'MON-YY') start_date FROM DUAL  as year
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial