Use nulls first or nulls last syntax in Oracle sequencing

Source: Internet
Author: User
Tags ming sorts

-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

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.