Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting Max Value(Date) from VARCHAR2 field

User910243567Feb 15 2017 — edited Feb 15 2017

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.

This post has been answered by jaramill on Feb 15 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2017
Added on Feb 15 2017
10 comments
2,531 views