SQL Order the calendar period using Oracle SQL

Viewed 77

I'm new in sql and I have question, hope you can help me.

How can I order the below data by calendar period. The datatype is VarChar2

Jan-2020
Feb-2020
Mar-2019
Jan-2019
Feb-2019
Mar-2020

Thank you in advance!

1 Answers

You can turn the string to a date to_date() and use it for ordering:

order by to_date(mycol, 'mon-yyyy')

If the language of your database or session is not English, you need an additional argument so Oracle can understand the month name:

    order by to_date(mycol, 'mon-yyyy', 'nls_date_language = american')
Related