drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array)
);
column table_name format a20
column column_name format a20
column json_modifier format a30
select table_name,
column_name,
json_modifier
from user_tab_cols
where json_modifier is not null
order by 1;
TABLE_NAME COLUMN_NAME JSON_MODIFIER
-------------------- -------------------- ------------------------------
T1 DATA JSON( ARRAY )
SQL>
insert into t1 (data)
values ('[{"fruit":"apple"},{"fruit":"banana"},{"fruit":"orangle"},{"fruit":"pear"}]'),
('[5,4,3,2,1]');
2 rows created.
SQL>
insert into t1 (data)
values ('{"fruit":"apple"}');
insert into t1 (data)
*
ERROR at line 1:
ORA-42700: jsontype ('OBJECT') instance does not match 'JSON( ARRAY )' type modifier
Help: https://docs.oracle.com/error-help/db/ora-42700/
SQL>
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number, 5, sort))
);
column table_name format a20
column column_name format a20
column json_modifier format a30
select table_name,
column_name,
json_modifier
from user_tab_cols
where json_modifier is not null
order by 1;
TABLE_NAME COLUMN_NAME JSON_MODIFIER
-------------------- -------------------- ------------------------------
T1 DATA JSON( ARRAY, NUMBER )
SQL>
insert into t1 (data)
values ('[5,4,3,2,1]');
select data from t1;
DATA
--------------------------------------------------
[1,2,3,4,5]
SQL>
insert into t1 (data)
values ('[6,5,4,3,2,1]');
insert into t1 (data)
*
ERROR at line 1:
ORA-42700: jsontype ('') instance does not match 'JSON( ARRAY (NUMBER, 3, SORT) )' type modifier
Help: https://docs.oracle.com/error-help/db/ora-42700/
SQL>
insert into t1 (data)
values ('[{"fruit":"apple"},{"fruit":"banana"},{"fruit":"orangle"}]');
insert into t1 (data)
*
ERROR at line 1:
ORA-42700: jsontype ('') instance does not match 'JSON( ARRAY (NUMBER, 3, SORT) )' type modifier
Help: https://docs.oracle.com/error-help/db/ora-42700/
SQL>
insert into t1 (data)
values ('[null,4,3,2,1]');
insert into t1 (data)
*
ERROR at line 1:
ORA-42700: jsontype ('') instance does not match 'JSON( ARRAY (NUMBER, 5, SORT) )' type modifier
Help: https://docs.oracle.com/error-help/db/ora-42700/
SQL>
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number allow null, 5, sort))
);
column table_name format a20
column column_name format a20
column json_modifier format a30
select table_name,
column_name,
json_modifier
from user_tab_cols
where json_modifier is not null
order by 1;
TABLE_NAME COLUMN_NAME JSON_MODIFIER
-------------------- -------------------- ------------------------------
T1 DATA JSON( ARRAY, NUMBER, NULL )
SQL>
insert into t1 (data)
values ('[null,4,3,2,1]');
select data from t1;
DATA
--------------------------------------------------
[null,1,2,3,4]
SQL>
-- Array of numbers. Implied disallow null, unlimited array size and no sort.
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number))
);
-- Array of numbers limited to 5 elements. Implied disallow null and no sort.
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number, 5))
);
-- Array of numbers limited to 5 sorted elements. Implied disallow null.
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number, 5, sort))
);
-- Array of numbers with unlimited elements and sorted. Implied disallow null.
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number, *, sort))
);
-- Array of numbers limited to 5 elements and sorted. Null values are allowed.
drop table if exists t1 purge;
create table t1 (
id number generated as identity primary key,
data json(array (number allow null, 5, sort))
);