Difference between SQL Server and Oracle in order

Source: Internet
Author: User

Today, we found a bug in the project, that is, about field sorting.

I wanted to get the result as follows:


However, the result is as follows: Put the A1 fan to the last one:


It is determined that it is not a plug-in problem, it must be an SQL problem. Because the original project is SQLServer, and then migrated to Oracle, this problem occurs.

The SQL statement of the original SQLServer is as follows, and there is no problem:


But in Oracle, it is like this:


In Oracle, you can delete the desc after tc. dataValue to achieve the expected results.

[Sqlserver]: sqlserver considers null to be the smallest. Sort in ascending order: null values are ranked first by default. To sort the values behind, order by case when col is null then 1 else 0 end and col sort in descending order: null values are ranked last by default. Order by case when col is null then 0 else 1 end, col desc [oracle]: oracle considers null to be the largest. Sort in ascending order. By default, the null value is placed behind. Sort in descending order. By default, the null value is ranked first. There are several ways to change this situation: (1) convert null to a specific value using the nvl function or decode function (2) convert null to a specific value using the case syntax (supported by later versions of oracle9i. Similar to sqlserver): order by (case mycol when null then 'Beijing drioker' else mycol end) www.2cto.com (3) Use nulls first or nulls last syntax. This is oracle's syntax for sorting null values. Nulls first: Place null at the top. For example, select * from mytb order by mycol nulls firstnull last: puts null at the end. For example, select * from mytb order by mycol nulls last


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.