drop table t
create table t (id number, col clob check (col IS JSON))
insert into t values(1, '{a:[1, "1", "cat", true, null, false, {}, ["dog","mouse"]], b:"json is fun"}')
commit
select t.col.a
from t t
select t.col.a[0]
from t t
select t.col.a[*]
from t t
select t.col.a[2 to 4]
from t t
select t.col.a.size()
from t t
select t.col.a[0].number()
from t t
select t.col.a[1].number()
from t t
select t.col.a[1].numberOnly()
from t t
select t.col.a[1].type()
from t t
select t.col.a[0].type()
from t t
select t.col.a.type()
from t t
select t.col.a[*].type()
from t t
drop table emp
create table emp (empno number, ename varchar2(10), job varchar2(9))
insert into emp values('7844', 'Turner', 'Clerk')
insert into emp values('7934', 'Ford', 'Analyst')
commit
with empjson as (select JSON_OBJECT('name' VALUE ename, 'empno' VALUE empno) "val" from emp)
select ej."val"."empno" from empjson ej
with empjson as (select (JSON_OBJECT('name' VALUE ename, 'empno' VALUE empno) || ' ') "val" from emp)
select ej."val"."empno" from empjson ej
create or replace function foo return varchar as
begin
return JSON_OBJECT('x' value '123');
end;
with plsqlFun as (select foo "foo" from dual)
select p."foo".x
from plsqlFun p
with plsqlFun as (select TREAT(foo AS JSON) "foo" from dual)
select p."foo".x
from plsqlFun p
with empjson as (select TREAT ((JSON_OBJECT('name' VALUE ename, 'empno' VALUE empno) || ' ') AS JSON) "val" from emp)
select ej."val"."empno"
from empjson ej
with empjson as (select TREAT ('{[/' AS JSON) "val" from dual)
select ej."val"."empno"
from empjson ej
with empjson as (select TREAT ('{[/' AS JSON) "val" from dual)
select ej."val"."empno"
from empjson ej
where ej."val" IS JSON
select JSON_VALUE(col, '$.a.type()')
from t
select JSON_VALUE(col, '$.a.size()')
from t
select JSON_VALUE(col, '$.a[*].type()')
from t
select JSON_VALUE(col, '$.a[*].type()' ERROR ON ERROR)
from t
select JSON_QUERY(col, '$.a[*].size()' with wrapper)
from t
select JSON_QUERY(col, '$.a[*].type().size()' with wrapper)
from t
select JSON_QUERY(col, '$.a[*].number()' with wrapper)
from t
select JSON_VALUE(col, '$.a[0]' returning NUMBER)
from t
select JSON_VALUE(col, '$.a[0].number()' )
from t
select JSON_VALUE(col, '$.a[1].number()' )
from t
select JSON_VALUE(col, '$.a[1].numberOnly()')
from t
select JSON_VALUE(col, '$.a[1].numberOnly()' ERROR ON ERROR )
from t
truncate table t
insert into t values(1,'{
"name": "Geeta",
"skills": [{
"skill": "testing",
"proficiency": 30
}, {
"skill": "java",
"proficiency": 85
}, {
"skill": "c",
"proficiency": 90
}]
}')
insert into t values(2,'{
"name": "Jonathan",
"skills": [{
"skill": "javascript",
"proficiency": 70
}, {
"skill": "python",
"proficiency": 100
}]
}')
insert into t values(3,'{}')
commit
select col from t t where t.col.skills.proficiency > 80
select t.col.skills.proficiency
from t t
select t.col.skills from t t
where JSON_EXISTS(col, '$.skills?(@.proficiency > 80)')
select JSON_QUERY(col,'$.skills?(@.proficiency > 80)' with conditional wrapper) from t
select JSON_QUERY(col,'$.skills[*]?(@.proficiency > 80)' with conditional wrapper) from t
select JSON_QUERY(col,'$.skills[*]?(@.proficiency > 80).skill' with conditional wrapper) from t
select JSON_QUERY(col,'$.skills[*]?(@.proficiency > 80).skill' with wrapper) from t
where JSON_EXISTS(col, '$.skills?(@.proficiency > 80)')
SELECT jt.*
FROM t,
JSON_TABLE(col, '$'
columns ("name" varchar2(30) path '$.name',
NESTED PATH '$.skills[*]'
columns ("skill_name" varchar2(20) path '$.skill',
"proficiency" NUMBER path '$.proficiency'))) jt
SELECT jt.*
FROM t NESTED col columns (name,
NESTED '$.skills[*]'columns (skill, proficiency)) jt
SELECT jt.*
FROM t NESTED col columns (name,
NESTED '$.skills[*]'columns (skill, proficiency NUMBER)) jt
explain plan for
select JSON_QUERY(col,'$.skills'),
JSON_QUERY(col,'$.skills[*]?(@.proficiency > 80).skill' with wrapper),
JSON_VALUE(col,'$.skills[*]?(@.proficiency > 80).skill[0]')
from t
where JSON_EXISTS(col, '$.skills?(@.proficiency > 80)')
select * from table(dbms_xplan.display)
desc emp
select JSON_OBJECT('name' value ename, 'position' value job) from emp
select JSON_OBJECT('name' : ename, 'position' : job) from emp
select JSON_OBJECT('name' : ename, job) from emp
select JSON_OBJECT(ename, job) from emp
select JSON_OBJECT(*) from emp