2.186 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_VARCHARValue:
TRUEorFALSE(default)Specifies the default return data type for the
JSON_QUERYfunction when theRETURNINGdata_typeclause is omitted.If you set this flag to
TRUE, then the return data type for theJSON_QUERYfunction isVARCHAR2(4000), regardless of its input data type.The default value of
FALSEcauses theJSON_QUERYfunction to use the data type of its input for the return data type. -
LAX_JSON_EXISTSValue:
TRUE(default) orFALSESpecifies the default type-compatibility for the
JSON_EXISTScondition when theTYPE(STRICT|LAX)clause is omitted.If you set this flag to
FALSE, then theJSON_EXISTScondition 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 theONERRORclause.The default value of
TRUEcauses theJSON_EXISTScondition 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_QUERYValue:
TRUE(default) orFALSESpecifies the default type-compatibility for the
JSON_QUERYfunction when theTYPE(STRICT|LAX)clause is omitted.If you set this flag to
FALSE, then theJSON_QUERYfunction 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 theONERRORclause.The default value of
TRUEcauses theJSON_QUERYfunction 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_TABLEValue:
TRUE(default) orFALSESpecifies the default type-compatibility for the
JSON_TABLEfunction when theTYPE(STRICT|LAX)clause is omitted.If you set this flag to
FALSE, then theJSON_TABLEfunction 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 theONERRORclause.The default value of
TRUEcauses theJSON_TABLEfunction 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_VALUEValue:
TRUE(default) orFALSESpecifies the default type-compatibility for the
JSON_VALUEfunction when theTYPE(STRICT|LAX)clause is omitted.If you set this flag to
FALSE, then theJSON_VALUEfunction 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 theONERRORclause.The default value of
TRUEcauses theJSON_VALUEfunction 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_ERRORValue:
ERRORorNULL(default)Specifies the default behavior for the functions
JSON_QUERY,JSON_TABLE(without theEXISTSclause), andJSON_VALUEwhen theONERRORclause 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
NULLcauses 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 AI Database 26ai.
See Also:
Oracle AI Database SQL
Language Reference for more information about the
JSON_QUERY, JSON_TABLE, and
JSON_VALUE functions, and the JSON_EXISTS
condition