• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql
You are here: Home / Oracle / function / NULLS LAST Function in Oracle SQL – PLSQL

NULLS LAST Function in Oracle SQL – PLSQL

November 21, 2012 by techhoneyadmin

The NULLS LAST Function in Oracle SQL / PLSQL is used to place the NULL records at the end in the fetched records.

Syntax for using the NULLS LAST function in Oracle SQL / PLSQL is ;
SELECT column(s)
ROW_NUMBER() OVER (ORDER BY column NULLS LAST)
FROM table_name;

Suppose we have a table named ‘employee’ as shown below:

Employee_ID Employee_Name Salary Department Commission
101 Emp A 10000 Sales 10
102 Emp B 20000 IT 20
103 Emp C 28000 IT 20
104 Emp D 30000 Support
105 Emp E 32000 Sales 10
106 Emp F 40000 Sales 10
107 Emp G 12000 Sales 10
108 Emp H 12000 Sales

Now, suppose we want to see the employee_name and commission and also want that the employee records having no commission should be listed LAST then we can achieve the same using NULLS LAST function as:

SELECT employee_name
       ,commission
       ,ROW_NUMBER () OVER (ORDER BY commission NULLS LAST) SNO
FROM employee;

We will get the following result:

Employee_Name Commission SNO
Emp G 10 1
Emp A 10 2
Emp E 10 3
Emp F 10 4
Emp B 20 5
Emp C 20 6
Emp H   7
Emp D   8

Here we can see that we have successfully fetched employees having no commission LAST in the list.


Filed Under: function Tagged With: how to use NULLS LAST function in oracle database query, how to use NULLS LAST function in oracle plsql, how to use NULLS LAST function in oracle sql, NULLS LAST function in oracle plsql, NULLS LAST function in oracle sql, NULLSLASTPLSQL, syntax and example of NULLS LAST function in oracle database query, syntax and example of NULLS LAST function in oracle plsql, syntax and example of NULLS LAST function in oracle sql, using NULLS LAST function in oracle database query, using NULLS LAST function in oracle plsql, using NULLS LAST function in oracle sql

Copyright © 2023 · Parallax Pro on Genesis Framework · WordPress · Log in