Introduction to Oracle SQL
Hadrien Lacroix
Content Developer
NULL evaluate to NULLNULL + 10 = NULLNULL valuesCOUNT doesn't count NULL values in a columnsReal world data isn't perfect.
= can't be used to test for NULL values
Instead use:
IS NULL SELECT * FROM Customer WHERE LastName IS NULL
IS NOT NULLSELECT * FROM Customer WHERE LastName IS NOT NULL
NVL(x, y): convert x, which may contain a null value, to y, a non-null value.
SELECT NVL(HireDate, '11/19/2004')
FROM Employee
NULLIF(x, y): Compares x and y, returns
NULL if x=yx if they are not equalSELECT c.CustomerId, i.BillingCity, c.City, NULLIF(i.BillingCity, c.City)
FROM Invoice i, Customer c
| CustomerId | BillingCity | City | NULLIF |
|------------|-------------|-----------|--------|
| 48 | Oslo | Amsterdam | Oslo |
| 49 | Boston | Vienne | Boston |
| 59 | London | London | NULL |
COALESCE: returns first non-null value in a list
SELECT CustomerId, COALESCE(phone, email, fax) AS ContactMethod
FROM Customer
| CustomerId | ContactMethod |
|------------|-------------------------|
| 59 | +91 080 22289999 |
| 58 | [email protected] |
| 57 | +56 (0)2 635 4444 |
Introduction to Oracle SQL