2.185 JSON_BEHAVIOR
JSON_BEHAVIOR
allows you to specify various default
behaviors, at the session level, for certain SQL/JSON functions and conditions.
Property | Description |
---|---|
Parameter type |
String |
Syntax |
There must be no spaces inside of the double quotation marks. |
Default value |
None |
Modifiable |
|
Modifiable in a PDB |
No |
Basic |
No |
This parameter allows you to change the default return data type, default type-compatibility, and default error behavior during a session for certain SQL/JSON functions and conditions. This lets you enforce consistent session-level JSON processing behavior, reducing the need for explicit overriding of default behaviors within individual SQL statements.
For example, by default, the JSON_QUERY
function uses
lax type-compatibility when comparing data. You can use this parameter to specify
that all invocations of the JSON_QUERY
function in a session use
strict type-compatibility, by default.
You can specify one or more of the following flags, in any order:
-
JSON_QUERY_RET_VARCHAR
Value:
TRUE
orFALSE
(default)Specifies the default return data type for the
JSON_QUERY
function when theRETURNING
data_type
clause is omitted.If you set this flag to
TRUE
, then the return data type for theJSON_QUERY
function isVARCHAR2(4000)
, regardless of its input data type.The default value of
FALSE
causes theJSON_QUERY
function to use the data type of its input for the return data type. -
LAX_JSON_EXISTS
Value:
TRUE
(default) orFALSE
Specifies the default type-compatibility for the
JSON_EXISTS
condition when theTYPE(STRICT|LAX)
clause is omitted.If you set this flag to
FALSE
, then theJSON_EXISTS
condition will behave as if were run withTYPE(STRICT)
syntax. That is, when searching for a value in an array, if an array value does not match the data type of the search value, then the condition will behave as specified by theON
ERROR
clause.The default value of
TRUE
causes theJSON_EXISTS
condition to behave as if it were run with the defaultTYPE(LAX)
syntax, and it will attempt to convert array values to the search value data type, when necessary. -
LAX_JSON_QUERY
Value:
TRUE
(default) orFALSE
Specifies the default type-compatibility for the
JSON_QUERY
function when theTYPE(STRICT|LAX)
clause is omitted.If you set this flag to
FALSE
, then theJSON_QUERY
function behaves as if it were run withTYPE(STRICT)
syntax. That is, when searching for a value in an array, if an array value does not match the data type of the search value, then the function will behave as specified by theON
ERROR
clause.The default value of
TRUE
causes theJSON_QUERY
function to behave as if it were run with the defaultTYPE(LAX)
syntax, and it will attempt to convert array values to the search value data type, when necessary. -
LAX_JSON_TABLE
Value:
TRUE
(default) orFALSE
Specifies the default type-compatibility for the
JSON_TABLE
function when theTYPE(STRICT|LAX)
clause is omitted.If you set this flag to
FALSE
, then theJSON_TABLE
function behaves as if were run withTYPE(STRICT)
syntax. That is, if the value of the function's chosen key is not of the specified return data type, then the function will behave as specified by theON
ERROR
clause.The default value of
TRUE
causes theJSON_TABLE
function to behave as if it were run with the defaultTYPE(LAX)
syntax, and it will attempt to convert the chosen key to the specified return data type, when necessary. -
LAX_JSON_VALUE
Value:
TRUE
(default) orFALSE
Specifies the default type-compatibility for the
JSON_VALUE
function when theTYPE(STRICT|LAX)
clause is omitted.If you set this flag to
FALSE
, then theJSON_VALUE
function behaves as if were run withTYPE(STRICT)
syntax. That is, if the function's return value is not of the specified return data type, then the function will behave as specified by theON
ERROR
clause.The default value of
TRUE
causes theJSON_VALUE
function to behave as if it were run with the defaultTYPE(LAX)
syntax, and it will attempt to convert the return value to the specified return data type, when necessary. -
ON_ERROR
Value:
ERROR
orNULL
(default)Specifies the default behavior for the functions
JSON_QUERY
,JSON_TABLE
(without theEXISTS
clause), andJSON_VALUE
when theON
ERROR
clause is omitted. By default, these functions return a null value in the event of an error, which can make it difficult to identify invalid queries.If you set this flag to
ERROR
, then these functions will return an error for invalid queries.The default value of
NULL
causes these functions to return a null value in the event of an error.
Examples
ALTER SESSION SET JSON_BEHAVIOR = "ON_ERROR:ERROR";
ALTER SESSION SET JSON_BEHAVIOR = "LAX_JSON_QUERY:FALSE;LAX_JSON_TABLE:FALSE;LAX_JSON_VALUE:FALSE";
Note:
This parameter is available starting with Oracle Database 23ai.
See Also:
Oracle Database SQL
Language Reference for more information about the
JSON_QUERY
, JSON_TABLE
, and
JSON_VALUE
functions, and the JSON_EXISTS
condition