As shown in the following table:
First use the str_to_date function to convert its varchar type to date type, and then sort from small to large
Syntax: select str_to_date(class_time,'%Y%m%d %H:%i:%s') a from a order by a desc;
Let’s take a look at the date format conversion of varchar type in oracle to date type
Varchar type date format conversion date type in oracle
SELECT to_char(to_date(m.ma_datetime,'yyyy-MM-dd hh24:mi:ss'), 'yyyyMMdd') FROM my_task m;
m.ma_datetime is a date format of varchar2 type, convert the date type first
(Hours, minutes and seconds must be added, otherwise ora-01830 error will be reported)
Then convert it to varchar type as you like