How can I get the cartesian product of the result of a string split with all entries in an array both being keys in a JSON object? This was the closest I got to the answer
SELECT REGEXP_SUBSTR(scp, '[^ ]+', 1, level), aud
FROM (SELECT scp, aud
FROM JSON_TABLE('{
"s": "s1 s2 s3",
"a": [
"a1",
"a2",
"a3"
]
}' FORMAT JSON,
'$[*]' COLUMNS(
scp VARCHAR2 PATH '$.s',
NESTED PATH '$.a[*]'
COLUMNS(
aud VARCHAR2 PATH '$[*]'
)
)
)
)
CONNECT BY REGEXP_SUBSTR(scp, '[^ ]+', 1, level) IS NOT NULL
but it is only exploding each s for a1. I am looking to get 9 entries, mapping each s to each a. How can this be achieved with a single JSON_TABLE query?
You cannot split a string using JSON functions.
You can split the string using simple string functions (which are much faster than regular expressions) and a recursive sub-query factoring clause:
From Oracle 12, you could also use
CROSS APPLY:Which both output:
fiddle