I'm trying to save a JSON array as database rows:
INSERT INTO log (
"uuid",
"date",
"msg",
"level"
)
WITH t ( log ) AS (
SELECT
JSON_QUERY('[{"uuid": "20000000-0000-0000-0000-000000000000", "date": "2021-10-17", "msg":"aaaa", "level": "debug" },
{"uuid": "20000000-0000-0000-0000-000000000000", "date": "2021-10-17", "msg":"bbbb", "level": "debug" }]'
, '$')
FROM
dual
)
SELECT
"uuid",
"date",
"msg",
"level"
FROM
t
CROSS JOIN
JSON_TABLE ( log, '$'
COLUMNS (
NESTED PATH '$[*]'
COLUMNS (
"uuid" VARCHAR2 ( 36 ) PATH '$.uuid',
"date" DATE PATH '$.date',
"msg" VARCHAR2 ( 1024 ) PATH '$.msg',
"level" VARCHAR2 ( 5 ) PATH '$.level'
)
)
)
When I try to use the %type
:
NESTED PATH '$[*]'
COLUMNS (
"uuid" VARCHAR2 ( 36 ) PATH '$.uuid',
"date" my_table.date%type PATH '$.date',
"msg" VARCHAR2 ( 1024 ) PATH '$.msg',
"level" VARCHAR2 ( 5 ) PATH '$.level'
)
I get an error:
SQL Error: ORA-40484: invalid data type for JSON_TABLE column
40484. 00000 - "invalid data type for JSON_TABLE column"
*Cause: A column in the provided JSON_TABLE had an unsupported data type.
*Action: Provide a supported data type.
Even though the type in the column is also date
.
Also the type char(36)
doesn't work, so I have to use VARCHAR2(36)
.
Is it possible to use %type
in this case?
CodePudding user response:
The JSON_TABLE
documentation gives the syntax for the JSON query column clause:
Following the link to the JSON_value_return_type
documentation tells you the allowable data types:
Given this, no, you cannot use %TYPE
or CHAR
as the JSON_TABLE
syntax does not allow it.