-Principle
Nulls first and Nulls last are the syntax supported by the Oracle order by, if an expression is specified in order by, the record that represents a null value is ranked at the top (either ASC or DESC) If the expression is specified in the ORDER by Nulls Nulls last indicates that the record of the null value will be at the end (either ASC or DESC) using the following syntax:--always place nulls in the top select * from ZL_CBQC ORDER by Cb_ld nulls first--Will nulls Always put in the last select * from ZL_CBQC ORDER by cb_ld Desc nulls last--Instance 1.order by Col (Asc/desc) nulls last no matter how Col sorts Col's null (null value ) always at the last sql> with TAB as (
2 SELECT 1 ID, ' xiaoming ' NAME, ' Dev Center ' dept from dual
3 UNION All
4 SELECT 2, ' Xiao Zhang ', ' development center ' from dual
5 UNION All
6 SELECT 3, ' Xiao Wang ', ' development center ' from dual
7 UNION All
8 SELECT 4, ' Xiao Li ', ' research Center ' from dual
9)
Ten SELECT *
One from (
SELECT ID, NAME, DEPT from tab
UNION All
+ SELECT NULL, DEPT, DEPT from tab GROUP by DEPT
15)
ORDER by DEPT, ID NULLS last
17/id NAME DEPT
---------- -------- --------
1 Xiao Ming Development Center
2 Xiao Zhang Development Center
3 Xiao Wang Development Center
Development Center Development Center
4 Xiao Li Research and Development Center
Research and Development Center has selected 6 lines. 2.order by Col (Asc/desc) NULLS first no matter how Col sorts Col's null (null value) always sql> EDI
Written to file Afiedt.buf 1 with TAB as (
2 SELECT 1 ID, ' xiaoming ' NAME, ' Dev Center ' dept from dual
3 UNION All
4 SELECT 2, ' Xiao Zhang ', ' development center ' from dual
5 UNION All
6 SELECT 3, ' Xiao Wang ', ' development center ' from dual
7 UNION All
8 SELECT 4, ' Xiao Li ', ' research Center ' from dual
9)
Ten SELECT *
One from (
SELECT ID, NAME, DEPT from tab
UNION All
+ SELECT NULL, DEPT, DEPT from tab GROUP by DEPT
15)
16* ORDER by DEPT, ID NULLS First
sql>/ID NAME DEPT
---------- -------- --------
Development Center Development Center
1 Xiao Ming Development Center
2 Xiao Zhang Development Center
3 Xiao Wang Development Center
Research and Development Center
4 Xiao Li Research and Development Center has selected 6 lines. Purpose: The original purpose is to bring together the same people in the department sql> EDI
Written to file Afiedt.buf 1 with TAB as (
2 SELECT 1 ID, ' xiaoming ' NAME, ' Dev Center ' dept from dual
3 UNION All
4 SELECT 2, ' Xiao Zhang ', ' development center ' from dual
5 UNION All
6 SELECT 3, ' Xiao Wang ', ' development center ' from dual
7 UNION All
8 SELECT 4, ' Xiao Li ', ' research Center ' from dual
9)
Ten SELECT id| | Name
One from (
SELECT ID, NAME, DEPT from tab
UNION All
+ SELECT NULL, DEPT, DEPT from tab GROUP by DEPT
15)
16* ORDER by DEPT, ID NULLS last
Sql>/id| | NAME
------------------------------------------------
1 xiaoming
2 small Sheets
3 Xiao Wang
Development Center
4 Xiao Li
The research and Development Center has selected 6 lines. This article transferred from: http://blog.csdn.net/zhangdaiscott/article/details/22870953
Use nulls first or nulls last syntax in Oracle sequencing