20.3 JSON_VALUE as JSON_TABLE
SQL/JSON function json_value
can be viewed as a special
case of function json_table
.
Example 20-7 illustrates the equivalence: the two SELECT
statements have the same effect.
In addition to perhaps helping you understand json_value
better, this equivalence is important practically, because it means that you can use either
function to get the same effect.
In particular, if you use json_value
more than once, or you use
it in combination with json_exists
or json_query
(which can
also be expressed using json_table
), to access the same data, then a single
invocation of json_table
presents the advantage that the data is parsed only
once.
Because of this, the optimizer often automatically rewrites multiple invocations
of json_exists
, json_value
and json_query
(any combination) to fewer invocations of json_table
.
Note:
You can use SQL hint NO_JSON_TABLE_TRANSFORM
to prevent rewriting of
multiple invocations of json_exists
, json_value
and json_query
(any combination) to fewer invocations of
json_table
.
Example 20-7 JSON_VALUE Expressed Using JSON_TABLE
SELECT json_value(column, json_path
RETURNING data_type error_hander ON ERROR)
FROM table;
SELECT jt.column_alias
FROM table,
json_table(column, '$' error_handler ON ERROR
COLUMNS ("COLUMN_ALIAS" data_type PATH json_path)) AS "JT";
Parent topic: SQL/JSON Function JSON_VALUE