Oracle's order by sort hollow string processing method

Source: Internet
Author: User


1, the default processing Oracle in order by default is considered null is the maximum value, so if it is ASC ascending is the last, desc descending is ranked in the top
2. Use the NVL function Nvl function to convert an input parameter to a specific value when null, such as NVL (Employee_Name, ' Zhang San ') to return ' Employee_Name ' when Zhang San is empty, and return employee_name if not empty This function allows you to customize the sort position of NULL.
3, using the Decode function decode function is more powerful than the NVL function, it can also convert the input parameters to a specific value when empty, such as decode (Employee_name,null, ' Zhang San ', employee_name) is indicated when the Employee_ ' Zhang San ' is returned when name is empty, and employee_name is returned if it is not empty this function allows you to customize the sort position of NULL.
4, using case syntax is supported after Oracle 9i, is a more flexible syntax, also can be applied in the sort, such as: SELECT * from the Employee Order by (box employee_name when null Then ' Zhang San ' else Employee_Name end) indicates that when the employee_name is empty it returns ' Zhang San ', and if not empty, the employee_name can also be ordered by the case syntax to customize the sort position of NULL.
5, using Nulls first or Nulls last syntax Nulls first and Nulls last is the syntax supported by the Oracle order by, if the expression is specified in order by, the record that represents the null value is ranked at the top ( Whether ASC or DESC) If the expression specified in the order by is nulls last then the record that represents the null value will be at the end (either ASC or DESC) using the syntax as follows:--nulls always placed in the top select * from ZL_CBQC ORDER by Cb_ld Nulls first-the nulls is always placed in the final select * from the ZL_CBQC ORDER by cb_ld Desc nulls Last

Oracle's order by sort hollow string processing method

Related Article

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.