I have requirement to get max value from specific column which is defined as VARCHAR2. The value which is stored in varchar2 column is date. (e.g '2017/01/31 00:00:00')
can you please suggest which of the below is correct though both are getting me correct value.
with t as
(select '2017/01/31 00:00:00' DATE1 FROM DUAL
UNION ALL
select '2017/02/06 00:00:00' FROM DUAL
UNION ALL
select '2017/03/05 00:00:00' FROM DUAL
UNION ALL
select '2017/04/02 00:00:00' FROM DUAL)
select TO_CHAR(MAX(TO_DATE(t.date1,'YYYY/MM/DD HH24:MI:SS')),'MON-RRRR') from t;
with t as
(select '2017/01/31 00:00:00' DATE1 FROM DUAL
UNION ALL
select '2017/02/06 00:00:00' FROM DUAL
UNION ALL
select '2017/03/05 00:00:00' FROM DUAL
UNION ALL
select '2017/04/02 00:00:00' FROM DUAL)
select TO_CHAR(TO_DATE(MAX(t.date1),'YYYY/MM/DD HH24:MI:SS'),'MON-RRRR') from t;
Thanks for your time.