How to format and sort a date in Oracle?

后端 未结 7 1884
长情又很酷
长情又很酷 2021-02-19 09:50

In my application am trying to format and sort the date, i am using to_char() function to format the date to my required format, but when i sort them it is sorting

7条回答
  •  旧时难觅i
    2021-02-19 10:26

    The easiest way is to retrieve the same field with the query again and doing sorting based upon that filed

    In your example

    SELECT 
             to_char( your_date_column, your_format_mask ) as formate_purpose,
             your_date_column as sorting_purpose
    FROM your_table
    
    ORDER BY your_date_column
    

提交回复
热议问题