JSON_SCALAR
The JSON_SCALAR function accepts a SQL scalar value as input and returns a corresponding JSON scalar value as a JSON type instance. The value can be an Oracle-specific JSON-language type, including types that are not part of the JSON standard (such as DATE).
Syntax
JSON_SCALAR(json_expr [NULL_clause] [JSON_SCALAR_on_error])
NULL_clause::= [{SQL|JSON}] NULL ON NULL | EMPTY STRING ON NULL
JSON_SCALAR_on_error::= {ERROR|NULL} ON ERRORParameters
JSON_SCALAR has the parameters:
| Parameter | Description |
|---|---|
|
|
Input to the The
json_expr parameter can be an instance of any of these SQL data types:
|
|
|
Optional clause used for SQL |
|
|
One of the options for SQL If the input to
JSON_SCALAR is a SQL NULL value, the return value is as follows:
You cannot specify this clause with the |
|
|
Another option for SQL If the input to You cannot specify this clause with the |
|
|
Optional clause that controls how error handling is processed. If you do not specify this clause, the default is Valid clauses are |
|
|
If there is an error, and you specify |
|
|
If there is an error, and you specify |
Description
-
The
JSON_SCALARfunction accepts a SQL scalar value as input and returns a corresponding JSON scalar value as a JSON type instance. -
The
JSON_SCALARfunction converts SQL scalar values into their corresponding JSON scalar representations. -
The input scalar value can be an Oracle-specific JSON-language type that is not part of the JSON standard, such as
DATEorTIMESTAMP. -
The
JSON_SCALARfunction does not parse input as JSON. -
The returned JSON type instance is a JSON-language scalar value supported by TimesTen. For example,
JSON_SCALAR(SYSDATE)returns an Oracle JSON value of typeDATE(as an instance of SQL data type JSON). -
If the input to
JSON_SCALARresults in a SQLNULLvalue, you can control the returned value by specifying theNULL_clause. For example,-
SQLNULLONNULL: Returns SQLNULL. -
JSONNULLONNULLorNULLONNULL: Returns JSONnull. -
EMPTYSTRINGONNULL: Returns an empty JSON string (" "). -
If you do not specify the
NULL_clause, the default return value is SQLNULL.
-
-
You can control error handling by specifying
ERRORONERRORorNULLONERROR. The default isERRORONERROR.
Examples
The following examples illustrate various uses of the JSON_SCALAR function.
The examples use ttIsql and are run from the ttIsql Command> prompt.
JSON_SCALAR with SYSDATE.SELECT JSON_SCALAR (SYSDATE);< "2026-03-05T21:37:18" >
1 row found.JSON_SCALAR with a numeric.SELECT JSON_SCALAR(1);< 1 >
1 row found.Let's create a table and store data of type JSON in a column. Let's drop the table first, in case it already exists.
DROP TABLE test;
CREATE TABLE test (col1 JSON);INSERT INTO test VALUES ('{a:100, b:200}');
INSERT INTO test VALUES ('{a:300}');Use JSON_SCALAR to return data from the JSON column.
SELECT JSON_SCALAR (ta.col1.b) FROM test ta;JSON_SCALAR returns SQL NULL for the second row.< 200 >
< <NULL> >
2 rows found.JSON NULL ON NULL clause to return JSON null instead of SQL NULL.SELECT JSON_SCALAR (ta.col1.b JSON NULL ON NULL) FROM test ta;< 200 >
< null >
2 rows found.Let's create a table and store data of type JSON in a column. Let's drop the table first, in case it already exists.
DROP TABLE test;
CREATE TABLE test (col1 JSON);
INSERT INTO test VALUES ('[{name:"abc"}, {name:"xyz"}]');1 row inserted.JSON_SCALAR to return a non-scalar type.SELECT JSON_SCALAR(ta.col1.name) FROM test ta;Sine JSON_SCALAR only supports scalar types, an error results.
2387: Json error: ORA-40575: JSON operation only supports scalar types.
The command failed.See Also
- JSON_SCALAR Function in the Oracle TimesTen In-Memory Database JSON Developer's Guide.