EMPTY STRING ON NULL for JSON Generation in Oracle Database 23ai/26ai
Oracle database 23ai/26ai has introduced the ability to convert nulls to empty strings during JSON generation.
oracle 23configurationintermediate
by OracleDba
16 views
Oracle database 23ai/26ai has introduced the ability to convert nulls to empty strings during JSON generation.
123456789101112131415161718192021222324252627
conn testuser1/testuser1@//localhost:1521/freepdb1
drop table if exists t1 purge;
create table t1 (
col1 VARCHAR2(10),
col2 VARCHAR2(10)
);
insert into t1
values ('ONE', 'TWO'),
('ONE', null),
(null, 'TWO'),
(null, null);
commit;
select rownum, col1, col2 from t1;
ROWNUM COL1 COL2
---------- ---------- ----------
1 ONE TWO
2 ONE
3 TWO
4
SQL>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
-- Implicit - NULL ON NULL.
select json_object(*) as data from t1;
DATA
--------------------------------------------------------------------------------
{"COL1":"ONE","COL2":"TWO"}
{"COL1":"ONE","COL2":null}
{"COL1":null,"COL2":"TWO"}
{"COL1":null,"COL2":null}
SQL>
-- Explicit - NULL ON NULL.
select json_object(* null on null) as data from t1;
DATA
--------------------------------------------------------------------------------
{"COL1":"ONE","COL2":"TWO"}
{"COL1":"ONE","COL2":null}
{"COL1":null,"COL2":"TWO"}
{"COL1":null,"COL2":null}
SQL>
select json_object(* absent on null) as data from t1;
DATA
--------------------------------------------------------------------------------
{"COL1":"ONE","COL2":"TWO"}
{"COL1":"ONE"}
{"COL2":"TWO"}
{}
SQL>
-- Default - ABSENT ON NULL
select json_array(col1) as data from t1;
DATA
--------------------------------------------------------------------------------
["ONE"]
["ONE"]
[]
[]
SQL>
-- Explicit - ABSENT ON NULL
select json_array(col1 absent on null) as data from t1;
DATA
--------------------------------------------------------------------------------
["ONE"]
["ONE"]
[]
[]
SQL>
-- NULL ON NULL
select json_array(col1 null on null) as data from t1;
DATA
--------------------------------------------------------------------------------
["ONE"]
["ONE"]
[null]
[null]
SQL>123456789101112131415161718192021
select json_object(* empty string on null) as data from t1;
DATA
--------------------------------------------------------------------------------
{"COL1":"ONE","COL2":"TWO"}
{"COL1":"ONE","COL2":""}
{"COL1":"","COL2":"TWO"}
{"COL1":"","COL2":""}
SQL>
select json_array(col1 empty string on null) as data from t1;
DATA
--------------------------------------------------------------------------------
["ONE"]
["ONE"]
[""]
[""]
SQL>Please to add comments
No comments yet. Be the first to comment!