How does oracle use order by to sort null values

  • 2021-01-03 21:08:18
  • OfStack

When oracle sorts query results, the sorted columns have an null value, and you specify that the NULL value comes first or last

Key words: Nulls First; Nulls Last

Default: null defaults to the maximum (i.e., asc ascending) < Small - > big > , null value ranked last; desc descending < Large - > small > , null comes first)

1.Oracle Order by supported syntax
2. Specifying Nulls first means that the record for the null value will rank first (whether asc or desc)
3. Specifying Nulls last means that the record of the null value will come last (either asc or desc)

Table: Tab_A field with partial null value Col_A
select * from Tab_A order by Tab_A. Col_A (asc/desc) nulls first------ > The null value comes first
select * from Tab_A order by Tab_A. Col_A (asc/desc) nulls last ------ > The null value comes last

Other methods:
In order by, Nvl, NVL2, Decode, case... when.... end; The null value of the field is processed by the
For example: select * from Tab_A order NVL (ES76en_ES77en. Col_A,'abc') (asc/desc);

Related articles: