Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Orakel - Abfrage von NULL-Werten in Unpivot-Abfrage

Verwenden Sie UNPIVOT INCLUDE NULLS :

SQL-Geige

Oracle 11g R2-Schema-Setup :

CREATE TABLE test ( id, a, b, c, d ) AS
SELECT 1, 1, 2, 3, 4 FROM DUAL UNION ALL
SELECT 2, 1, NULL, 3, NULL FROM DUAL;

Abfrage 1 :

SELECT *
FROM   test
UNPIVOT INCLUDE NULLS ( value FOR name IN ( a, b, c, d ) )

Ergebnisse :

| ID | NAME |  VALUE |
|----|------|--------|
|  1 |    A |      1 |
|  1 |    B |      2 |
|  1 |    C |      3 |
|  1 |    D |      4 |
|  2 |    A |      1 |
|  2 |    B | (null) |
|  2 |    C |      3 |
|  2 |    D | (null) |