DB2 Table functions - UNNEST
The UNNEST function returns a result table that includes a row for each element of the specified array. If there are multiple ordinary array arguments specified, the number of rows will match the array with the largest cardinality.
The schema is SYSIBM.
Names for the result columns produced by the UNNEST function can be provided as part of the correlation-clause of the collection-derived-table clause.
The UNNEST function can only be used in a collection-derived-table clause in a context where arrays are supported (SQLSTATE 42887).
The result table depends on the input arguments.
This special table function is only used in collection-derived-table of table-reference in a FROM clause.
If more than one array is provided and at least one of the arguments is an associative array, an error is returned (SQLSTATE 42884).
If the WITH ORDINALITY clause is used when unnesting an associative array, an error is returned (SQLSTATE 428HT).
SELECT T.ID , T.NUM FROM UNNEST(RECENT_CALLS) WITH ORDINALITY AS T(NUM, ID)
ID NUM ---- ---- 1 9055553907 2 4165554213 3 4085553678
SELECT T.ID , T.PHONE FROM UNNEST(PHONELIST) AS T(ID, PHONE)
ID PHONE ----- ---------- Home 4163053745 Work 4163053746 Mom 4164789683