Skip to content
Advertisement

How to write this kind of query in Oracle

I have a MySQL database and I want to migrate all query to Oracle and since I am not an expert in Oracle SQL I am stuck here.

I have query like this

ORDER BY 
   WEEK(`Date`) DESC, `Date` DESC";

My question is: How to write this ORDER BY expression in Oracle SQL?

Advertisement

Answer

You can use

ORDER BY TO_NUMBER(TO_CHAR(date_col,'iw','NLS_DATE_LANGUAGE=English')) DESC, date_col DESC
  • There is no column naming format containing back ticks in Oracle, and date is a reserved keyword (not allowed to use as a column name)

  • TO_NUMBER() is needed, since WEEK() function in MySQL returns a numeric value.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement