Oracle uses order by to sort null values

Source: Internet
Author: User

Applicability:
When oracle sorts the query results, the column to be sorted has a null value, and the NULL value must be specified at the beginning or end of the column.

Keywords: Nulls First; Nulls Last

Default Value: the default value of null is the maximum value (I .e., asc in ascending order <small --> large>. The value of null is at the end; desc in descending order <large --> small>, the null value is at the top)

Specify:
1. Syntax supported by Oracle Order
2. If Nulls first is specified, the null value of the record will be ranked first (whether asc or desc)
3. Specifying Nulls last indicates that the records with null values will be placed at the end (whether asc or desc)

Syntax example:( Table: Columns with some null values in Tab_A)
Select * from Tab_A order by Tab_A. Col_A (asc/desc) nulls first ------> the null value ranks first.
Select * from Tab_A order by Tab_A. Col_A (asc/desc) nulls last ------> the null value is placed at the end

Other methods:
In order by, use functions such as Nvl, NVL2, Decode, case... when... end; to process the null values of the column.
Example: select * from Tab_A order by NVL (Tab_A. Col_A, 'abc') (asc/desc );

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.