Introduction à Oracle SQL
Hadrien Lacroix
Content Developer
NULL donnent NULLNULL + 10 = NULLNULLCOUNT ne compte pas les NULL dans une colonneLes données réelles ne sont pas parfaites.
= ne permet pas de tester les valeurs NULL
Utilisez plutôt :
IS NULL SELECT * FROM Customer WHERE LastName IS NULL
IS NOT NULLSELECT * FROM Customer WHERE LastName IS NOT NULL
NVL(x, y) : convertit x, qui peut être NULL, en y, une valeur non nulle.
SELECT NVL(HireDate, '11/19/2004')
FROM Employee
NULLIF(x, y) : compare x et y, renvoie
NULL si x=yx s'ils sont différentsSELECT 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 : renvoie la première valeur non nulle d'une liste
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 à Oracle SQL