In data development applications, data needs to be sorted in most cases. However, in Oracle databases, there is a NULL value ). If some values in a column are empty, if this column is sorted, the rows with null values are sorted at the end, for example, if I sort the EMPLOYEES in HR mode by commission rate,
SELECT t. employee_id, t. last_name, t. commission_pct
FROM employees t
WHERE t. employee_id BETWEEN 178 AND 181
Order by t. commission_pct
The result is as follows:
179 Johnson 0.10
178 Grant 0.15
180 Taylor
181 Fleaur
180,181 due to no commission ratio
In some cases, we want to sort records with null values before rather than after them. In this case, we need to use keywords:
Nulls first: sorts records with null values before
Nulls last: sorts records with null values (default)
For example, make a few changes in the above example:
SELECT t. employee_id, t. last_name, t. commission_pct
FROM employees t
WHERE t. employee_id BETWEEN 178 AND 181
Order by t. commission_pct NULLS FIRST
The result is as follows:
180 Taylor
181 Fleaur
179 Johnson 0.10
178 Grant 0.15
180,181 no commission rate is pushed to the front