user13541818
user13541818

Reputation:

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?

Upvotes: 0

Views: 41

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65408

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.

Upvotes: 1

Related Questions