Programming
HR
Emulating SQL FILTER with Oracle JSON Aggregate Functions
['View All Posts Lukaseder', 'I Made Jooq']
Java, SQL and jOOQ.
|["1984","Animal Farm",null,null,null]|{"id-1":null,"id-4":"Brida","id-3":null,"id-2":null,"id-17":null}| E.g. while id-3 and id-2 values are NULL because the FILTER emulating CASE expression maps them to NULL , the id-17 value really has a NULL title. SELECT JSON_TRANSFORM( JSON_ARRAYAGG( CASE WHEN T_BOOK.LANGUAGE_ID = 1 -- Wrap legitimate data into an array, including nulls THEN JSON_ARRAY(T_BOOK.TITLE NULL ON NULL) END -- Remove NULLs due to FILTER emulation ABSENT ON NULL ), -- Unwrap data gain from the array NESTED PATH '$[*]' (REPLACE '@' = PATH '@[0]') ), JSON_TRANSFORM( JSON_OBJECTAGG( 'id-' || T_BOOK.ID, CASE WHEN T_BOOK.LANGUAGE_ID = 2 -- Wrap legitimate data into an array, including nulls THEN JSON_ARRAY(T_BOOK.TITLE NULL ON NULL) END -- Remove NULLs due to FILTER emulation…