Sorting of null values

Source: Internet
Author: User


Oracle sorting of null values: 1. Oracle determines that NULL is the maximum value by default when Order by is used, therefore, if ASC is in ascending order, it is at the end, and DESC is in descending order. 2. When the input parameter is null, use the nvl function www.2cto.com nvl to convert it to a specified value, for example, nvl (employee_name, 'zhang san') indicates that when employee_name is empty, 'zhang san' is returned. If not empty, the return value is employee_name. This function allows you to customize the null sorting position. 3. the decode function is more powerful than the nvl function. It can also convert an input parameter to a specified value when it is null, such as decode (employee_name, null, 'zhangsan ', employee_name) indicates that when the value of employee_name is null, 'zhang san' is returned. If the value is not null, the return value is employee_name. This function can be used to customize the null sorting position. 4. The case syntax is supported after Oracle 9i. It is a flexible syntax, and www.2cto.com can also be used in sorting, for example: select * from employee order by (case employee_name when null then 'zhang san' else employee_name www.2cto.com end) indicates that when employee_name is null, 'zhang san' is returned ', if it is not null, the return value is "employee_name". The case syntax can also be used to customize the null sorting position. 5. Use nulls first or nulls last syntax Nulls first and nulls last are the syntaxes supported by Oracle Order by. If the expression Nulls first is specified in Order by, the records with null values are ranked first. (whether asc or desc) if the expression Nulls last is specified in Order by, the records with null values will be placed at the end (whether asc or desc) use the syntax www.2cto.com to always put nulls at the beginning select * from zl_cbqc order by cb_ld nulls first // cb_ld is null always at the beginning put nulls always at the end select * from zl_cbqc order by cb_ld desc 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.