Useful shortcuts for vi editor

Friday, 30 March 2018

NULLS LAST keyword usage

-> HR.EMPLOYEES will be test table.
SQL> 
DESC HR.EMPLOYEES;

e.g.
To populate all data
SQL> 
SELECT * FROM HR.EMPLOYEES;

To manipulate data by "COMMISSION_PCT" column descending order.
SQL> 
  SELECT *
    FROM HR.EMPLOYEES
ORDER BY COMMISSION_PCT DESC;

-> This is wrong query cause "NULL" columns show on top. Therefore, "NULLS LAST" keyword should be used.
SQL>
  SELECT *
    FROM HR.EMPLOYEES
ORDER BY COMMISSION_PCT DESC NULLS LAST;