SlideShare une entreprise Scribd logo
Store non-structured data in JSON column types and
enhancements of JSON in new versions of Oracle
JSON data type is one of the important and essential features that is available in Oracle.
Without Json support, any databases have a challenge for compatibility and exchange data ,
migration data with other and new systems such as bigdata, data science, developers usage, ...
JSON (JavaScript Object Notation) is a lightweight format that is used for data
interchanging. It is based on a subset of JavaScript language (the way objects are built in
JavaScript). As stated in the MDN, some JavaScript is not JSON, and some JSON is not
JavaScript.
An example of where this is used is web services responses. In the 'old' days, web services used
XML as their primary data format for transmitting back data, but since JSON appeared (The JSON
format is speci
fi
ed in RFC 4627 by Douglas Crockford), it has been the preferred format because it
is much more lightweight
JSON is built on two structures:
• A collection of name/value pairs. In various languages, this is realized as an object, record,
struct, dictionary, hash table, keyed list, or associative array.
• An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
Oracle Database support for JavaScript Object Notation (JSON) is designed to provide the best
fi
t
between the worlds of relational storage and querying JSON data, allowing relational and JSON
queries to work well together. Oracle SQL/JSON support is closely aligned with the JSON support
in the SQL Standard.
In a relational database, it’s best to store data according to the principles of the relational model.
However, it might be that you also need to store non-structured data, in which case, a JSON
column can help you deal with such a requirement.
JSON data features is going on to improve in new versions and
fi
nally in 23c, Oracle achieved
very new and amazing features on the JSON.
The Proble
Prior to Oracle 21c, all JSON data was stored in the database as text, typically in columns with
data types such as BLOB, CLOB or VARCHAR2. With the introduction of the JSON data type in
Oracle 21c, people may wish to convert their text-based JSON columns to use the JSON data
type. There are several methods to do this, including the following.
• CREATE TABLE ... AS SELECT (CTAS)
• Data Pump
• Online Table Rede
fi
nition
• Add the new column and perform a DML update
In all cases we don't know if the data in the column is suitable for such a conversion until we
attempt it.
The Solution :
DBMS_JSON.JSON_TYPE_CONVERTIBLE_CHECK
In Oracle 23c the JSON_TYPE_CONVERTIBLE_CHECK procedure has been added to the
DBMS_JSON package.
This procedure allows us to perform a pre-migration check on the contents of the text-based
JSON column, to make sure it is suitable for conversion to a JSON data type column.
I run the JSON_TYPE_CONVERTIBLE_CHECK procedure, passing in the column of interest, and a
status table name. This table will be created.
create table json_data (
id number generated always as identity,
data clob
);
We populate it with three rows that are suitable for conversion to a JSON data type column.
insert into json_data (data)
values (null);
insert into json_data (data)
values ('{}');
insert into json_data (data)
values ('{"product":"banana", "quantity":10}');
commit;
begin
dbms_json.json_type_convertible_check(
owner => 'testuser1',
tablename => 'json_data',
columnname => 'data',
statustablename => 'json_data_precheck'
);
end;
/
select status from json_data_precheck;
Result: Process completed (Errors found: 0)
SQL>
If status contains any error we must resolve it and error means column contents is incomplete
with json type.
Migrate the Data to a JSON Column
We can now move forward and convert the data using one of the valid methods.
-- Add a JSON column,
alter table json_data add (
data2 json
);
-- Populate the new column.
update json_data
set data2 = JSON(data);
-- Drop the old column. You may prefer to mark it as unused.
alter table json_data drop column data;
-- Rename the new column to match the original name.
alter table json_data rename column data2 to data;
In Oracle 21c we can add a JSON column type:
CREATE TABLE book (
id NUMBER(19, 0) NOT NULL PRIMARY KEY,
isbn VARCHAR2(15 CHAR),
properties JSON);
If you’re using Oracle 12c, 18c, 19c you can store JSON objects in VARCHAR2, BLOB, or CLOB
column types.
It’s recommended to store small JSON objects so they can
fi
t in a VARCHAR2(4000) column and,
therefore,
fi
t into the Bu
ff
er Pool page.
When you create the table, you can validate the stored JSON objects using a CHECK constraint:
CREATE TABLE book (
id NUMBER(19, 0) NOT NULL PRIMARY KEY,
isbn VARCHAR2(15 CHAR),
properties VARCHAR2(4000)
CONSTRAINT ENSURE_JSON CHECK (properties IS JSON));
To index JSON attributes that have high selectivity, you can use a B+Tree index:
CREATE INDEX book_properties_title_idx
ON book (properties.title);
To index JSON attributes that have low selectivity, such as boolean or Enum values, you can use
a BITMAP index:
CREATE BITMAP INDEX book_properties_reviews_idx
ON book (JSON_EXISTS(properties,'$.reviews'));
Because a bitmap index record references many rows of the associated indexed table, concurrent
UPDATE or DELETE statements can lead to concurrency issues (e.g., deadlocks, lock timeouts,
high response times).
For this reason, they are useful for read-only columns or if the column values change very
infrequently.
You can also use a generic SEARCH index for the JSON column, which will allow you to match
key/value JSON attribute data:
CREATE SEARCH INDEX book_search_properties_idx
ON book (properties) FOR JSON;
When we insert json values may have some syntax error on inserting. In 23c this problem is
resolved by following:
VALIDATE Keyword With IS JSON Condition
We can use VALIDATE as part of an IS JSON condition. In the following example we recreate the
table, this time using the IS JSON condition as part of a check contraint.
drop table if exists t1 purge;
create table t1 (
id number,
json_data json,
constraint t1_pk primary key (id),
constraint json_data_chk check (json_data is json validate '{
"type" : "object",
"properties" : {"fruit" : {"type" : "string",
"minLength" : 1,
"maxLength" : 10},
"quantity" : {"type" : "number",
"minimum" : 0,
"maximum" : 100}},
"required" : ["fruit", "quantity"]
}')
);
We can also use the VALIDATE keyword with an IS JSON condition in a query.
Also we can use this feature when doing select :
select *
from t1
where json_data is json validate '{
"type" : "object",
"properties" : {"fruit" : {"type" : "string",
"minLength" : 1,
"maxLength" : 10},
"quantity" : {"type" : "number",
"minimum" : 0,
"maximum" : 100}},
"required" : ["fruit", "quantity"]
}';
Finaly above query only list standard and without syntax error records in result.
DBMS_JSON_SCHEMA.IS_SCHEMA_VALID
The IS_SCHEMA_VALID function in the DBMS_JSON_SCHEMA package can check the validity of
a JSON schema de
fi
nition. In the following example we call it with a valid JSON schema, then an
invalid one.
Sql>
select dbms_json_schema.is_schema_valid('{
"type" : "object",
"properties" : {"fruit" : {"type" : "string",
"minLength" : 1,
"maxLength" : 10},
"quantity" : {"type" : "number",
"minimum" : 0,
"maximum" : 100}},
"required" : ["fruit", "quantity"]
}') as is_valid;
IS_VALID
----------
1
SQL>
select dbms_json_schema.is_schema_valid('banana') as is_valid;
*
ERROR at line 1:
ORA-40441: JSON syntax error
SQL>
-----------------------
Regards,
Alireza Kamrani
Senior RDBMS Consultant.

Contenu connexe

Similaire à Store non-structured data in JSON column types and enhancements of JSON

JSON in Oracle 18c and 19c
JSON in Oracle 18c and 19cJSON in Oracle 18c and 19c
JSON in Oracle 18c and 19c
stewashton
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
dyumna2
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
Jaya Naresh Kovela
 
Json
JsonJson
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
Ivo Andreev
 
Json
JsonJson
JSON in 18c and 19c
JSON in 18c and 19cJSON in 18c and 19c
JSON in 18c and 19c
stewashton
 
Working with JSON.pptx
Working with JSON.pptxWorking with JSON.pptx
Working with JSON.pptx
Lovely Professional University
 
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
Ryan B Harvey, CSDP, CSM
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
AmitSharma397241
 
Json
JsonJson
Json in 18c and 19c
Json in 18c and 19cJson in 18c and 19c
Json in 18c and 19c
stewashton
 
Json
JsonJson
Json
Uma mohan
 
Working with JSON
Working with JSONWorking with JSON
MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge share
Mr Kyaing
 
Json
JsonJson
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
Skillwise Group
 
Mindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developersMindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developers
Keshav Murthy
 
Json
JsonJson
Json
soumya
 

Similaire à Store non-structured data in JSON column types and enhancements of JSON (20)

JSON in Oracle 18c and 19c
JSON in Oracle 18c and 19cJSON in Oracle 18c and 19c
JSON in Oracle 18c and 19c
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Json
JsonJson
Json
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Native JSON Support in SQL2016
Native JSON Support in SQL2016Native JSON Support in SQL2016
Native JSON Support in SQL2016
 
Json
JsonJson
Json
 
JSON in 18c and 19c
JSON in 18c and 19cJSON in 18c and 19c
JSON in 18c and 19c
 
Working with JSON.pptx
Working with JSON.pptxWorking with JSON.pptx
Working with JSON.pptx
 
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
JSON Processing in the Database using PostgreSQL 9.4 :: Data Wranglers DC :: ...
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
 
Json
JsonJson
Json
 
Json in 18c and 19c
Json in 18c and 19cJson in 18c and 19c
Json in 18c and 19c
 
Json
JsonJson
Json
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge share
 
Json
JsonJson
Json
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
Mindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developersMindmap: Oracle to Couchbase for developers
Mindmap: Oracle to Couchbase for developers
 
Json
JsonJson
Json
 

Plus de Alireza Kamrani

How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource ManagerHow To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
Alireza Kamrani
 
Oracle PDB Failover in a Data Guard environment
Oracle PDB Failover in a Data Guard environmentOracle PDB Failover in a Data Guard environment
Oracle PDB Failover in a Data Guard environment
Alireza Kamrani
 
Using PDB Relocation to Move a Single PDB to Another Existing CDB
Using PDB Relocation to Move a Single PDB to Another Existing CDBUsing PDB Relocation to Move a Single PDB to Another Existing CDB
Using PDB Relocation to Move a Single PDB to Another Existing CDB
Alireza Kamrani
 
Recovering a oracle datafile without backup
Recovering a oracle datafile without backupRecovering a oracle datafile without backup
Recovering a oracle datafile without backup
Alireza Kamrani
 
EDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in Oracle
EDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in OracleEDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in Oracle
EDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in Oracle
Alireza Kamrani
 
Oracle Application Continuity with Oracle RAC for java
Oracle Application Continuity with Oracle RAC for javaOracle Application Continuity with Oracle RAC for java
Oracle Application Continuity with Oracle RAC for java
Alireza Kamrani
 
Oracle database maximum performance on Exadata
Oracle database maximum performance on ExadataOracle database maximum performance on Exadata
Oracle database maximum performance on Exadata
Alireza Kamrani
 
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdfClone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Alireza Kamrani
 
Flashback time travel vs Flash back Data Archive.pdf
Flashback time travel  vs Flash back Data Archive.pdfFlashback time travel  vs Flash back Data Archive.pdf
Flashback time travel vs Flash back Data Archive.pdf
Alireza Kamrani
 
Import option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdfImport option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdf
Alireza Kamrani
 
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
Alireza Kamrani
 
Recovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdfRecovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdf
Alireza Kamrani
 
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
Alireza Kamrani
 
♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance
Alireza Kamrani
 
Out-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden ImagesOut-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden Images
Alireza Kamrani
 
IO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performanceIO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performance
Alireza Kamrani
 
The Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAsThe Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAs
Alireza Kamrani
 
What is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of databaseWhat is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of database
Alireza Kamrani
 
🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...
Alireza Kamrani
 
Oracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking featuresOracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking features
Alireza Kamrani
 

Plus de Alireza Kamrani (20)

How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource ManagerHow To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
 
Oracle PDB Failover in a Data Guard environment
Oracle PDB Failover in a Data Guard environmentOracle PDB Failover in a Data Guard environment
Oracle PDB Failover in a Data Guard environment
 
Using PDB Relocation to Move a Single PDB to Another Existing CDB
Using PDB Relocation to Move a Single PDB to Another Existing CDBUsing PDB Relocation to Move a Single PDB to Another Existing CDB
Using PDB Relocation to Move a Single PDB to Another Existing CDB
 
Recovering a oracle datafile without backup
Recovering a oracle datafile without backupRecovering a oracle datafile without backup
Recovering a oracle datafile without backup
 
EDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in Oracle
EDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in OracleEDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in Oracle
EDITION & TARGET EDITION & Edition-Based Redefinition (EBR) in Oracle
 
Oracle Application Continuity with Oracle RAC for java
Oracle Application Continuity with Oracle RAC for javaOracle Application Continuity with Oracle RAC for java
Oracle Application Continuity with Oracle RAC for java
 
Oracle database maximum performance on Exadata
Oracle database maximum performance on ExadataOracle database maximum performance on Exadata
Oracle database maximum performance on Exadata
 
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdfClone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
Clone_a_remote_PDB_in_Data_Guard_Environments_19c_1698741799.pdf
 
Flashback time travel vs Flash back Data Archive.pdf
Flashback time travel  vs Flash back Data Archive.pdfFlashback time travel  vs Flash back Data Archive.pdf
Flashback time travel vs Flash back Data Archive.pdf
 
Import option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdfImport option in Oracle Database : tip & trick🧶.pdf
Import option in Oracle Database : tip & trick🧶.pdf
 
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
🔴Oracle ASM Filter Driver & ASMLIB & UDEV🔴.pdf
 
Recovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdfRecovering a Oracle datafile without backup.pdf
Recovering a Oracle datafile without backup.pdf
 
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
♨️How To Use DataPump (EXPDP) To Export From Physical Standby….pdf
 
♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance♨️CPU limitation per Oracle database instance
♨️CPU limitation per Oracle database instance
 
Out-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden ImagesOut-of-Place Oracle Database Patching and Provisioning Golden Images
Out-of-Place Oracle Database Patching and Provisioning Golden Images
 
IO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performanceIO Schedulers (Elevater) concept and its affection on database performance
IO Schedulers (Elevater) concept and its affection on database performance
 
The Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAsThe Fundamental Characteristics of Storage concepts for DBAs
The Fundamental Characteristics of Storage concepts for DBAs
 
What is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of databaseWhat is Scalability and How can affect on overall system performance of database
What is Scalability and How can affect on overall system performance of database
 
🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...
 
Oracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking featuresOracle Database 23c–Fine Grained locking features
Oracle Database 23c–Fine Grained locking features
 

Dernier

一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
ytypuem
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
dataschool1
 
REUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptx
REUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptxREUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptx
REUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptx
KiriakiENikolaidou
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
eudsoh
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
1tyxnjpia
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
Timothy Spann
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
zsafxbf
 
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
osoyvvf
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
mkkikqvo
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
xclpvhuk
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
jitskeb
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
oaxefes
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
tzu5xla
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
slg6lamcq
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
actyx
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
lzdvtmy8
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 

Dernier (20)

一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
 
REUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptx
REUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptxREUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptx
REUSE-SCHOOL-DATA-INTEGRATED-SYSTEMS.pptx
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
 
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
06-12-2024-BudapestDataForum-BuildingReal-timePipelineswithFLaNK AIM
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
 
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
一比一原版南十字星大学毕业证(SCU毕业证书)学历如何办理
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 

Store non-structured data in JSON column types and enhancements of JSON

  • 1. Store non-structured data in JSON column types and enhancements of JSON in new versions of Oracle JSON data type is one of the important and essential features that is available in Oracle. Without Json support, any databases have a challenge for compatibility and exchange data , migration data with other and new systems such as bigdata, data science, developers usage, ... JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language (the way objects are built in JavaScript). As stated in the MDN, some JavaScript is not JSON, and some JSON is not JavaScript. An example of where this is used is web services responses. In the 'old' days, web services used XML as their primary data format for transmitting back data, but since JSON appeared (The JSON format is speci fi ed in RFC 4627 by Douglas Crockford), it has been the preferred format because it is much more lightweight JSON is built on two structures: • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. Oracle Database support for JavaScript Object Notation (JSON) is designed to provide the best fi t between the worlds of relational storage and querying JSON data, allowing relational and JSON queries to work well together. Oracle SQL/JSON support is closely aligned with the JSON support in the SQL Standard. In a relational database, it’s best to store data according to the principles of the relational model. However, it might be that you also need to store non-structured data, in which case, a JSON column can help you deal with such a requirement. JSON data features is going on to improve in new versions and fi nally in 23c, Oracle achieved very new and amazing features on the JSON. The Proble Prior to Oracle 21c, all JSON data was stored in the database as text, typically in columns with data types such as BLOB, CLOB or VARCHAR2. With the introduction of the JSON data type in Oracle 21c, people may wish to convert their text-based JSON columns to use the JSON data type. There are several methods to do this, including the following. • CREATE TABLE ... AS SELECT (CTAS) • Data Pump • Online Table Rede fi nition • Add the new column and perform a DML update In all cases we don't know if the data in the column is suitable for such a conversion until we attempt it.
  • 2. The Solution : DBMS_JSON.JSON_TYPE_CONVERTIBLE_CHECK In Oracle 23c the JSON_TYPE_CONVERTIBLE_CHECK procedure has been added to the DBMS_JSON package. This procedure allows us to perform a pre-migration check on the contents of the text-based JSON column, to make sure it is suitable for conversion to a JSON data type column. I run the JSON_TYPE_CONVERTIBLE_CHECK procedure, passing in the column of interest, and a status table name. This table will be created. create table json_data ( id number generated always as identity, data clob ); We populate it with three rows that are suitable for conversion to a JSON data type column. insert into json_data (data) values (null); insert into json_data (data) values ('{}'); insert into json_data (data) values ('{"product":"banana", "quantity":10}'); commit; begin dbms_json.json_type_convertible_check( owner => 'testuser1', tablename => 'json_data', columnname => 'data', statustablename => 'json_data_precheck' ); end; / select status from json_data_precheck; Result: Process completed (Errors found: 0) SQL> If status contains any error we must resolve it and error means column contents is incomplete with json type. Migrate the Data to a JSON Column We can now move forward and convert the data using one of the valid methods. -- Add a JSON column, alter table json_data add ( data2 json ); -- Populate the new column. update json_data set data2 = JSON(data); -- Drop the old column. You may prefer to mark it as unused.
  • 3. alter table json_data drop column data; -- Rename the new column to match the original name. alter table json_data rename column data2 to data; In Oracle 21c we can add a JSON column type: CREATE TABLE book ( id NUMBER(19, 0) NOT NULL PRIMARY KEY, isbn VARCHAR2(15 CHAR), properties JSON); If you’re using Oracle 12c, 18c, 19c you can store JSON objects in VARCHAR2, BLOB, or CLOB column types. It’s recommended to store small JSON objects so they can fi t in a VARCHAR2(4000) column and, therefore, fi t into the Bu ff er Pool page. When you create the table, you can validate the stored JSON objects using a CHECK constraint: CREATE TABLE book ( id NUMBER(19, 0) NOT NULL PRIMARY KEY, isbn VARCHAR2(15 CHAR), properties VARCHAR2(4000) CONSTRAINT ENSURE_JSON CHECK (properties IS JSON)); To index JSON attributes that have high selectivity, you can use a B+Tree index: CREATE INDEX book_properties_title_idx ON book (properties.title); To index JSON attributes that have low selectivity, such as boolean or Enum values, you can use a BITMAP index: CREATE BITMAP INDEX book_properties_reviews_idx ON book (JSON_EXISTS(properties,'$.reviews')); Because a bitmap index record references many rows of the associated indexed table, concurrent UPDATE or DELETE statements can lead to concurrency issues (e.g., deadlocks, lock timeouts, high response times). For this reason, they are useful for read-only columns or if the column values change very infrequently. You can also use a generic SEARCH index for the JSON column, which will allow you to match key/value JSON attribute data: CREATE SEARCH INDEX book_search_properties_idx ON book (properties) FOR JSON; When we insert json values may have some syntax error on inserting. In 23c this problem is resolved by following:
  • 4. VALIDATE Keyword With IS JSON Condition We can use VALIDATE as part of an IS JSON condition. In the following example we recreate the table, this time using the IS JSON condition as part of a check contraint. drop table if exists t1 purge; create table t1 ( id number, json_data json, constraint t1_pk primary key (id), constraint json_data_chk check (json_data is json validate '{ "type" : "object", "properties" : {"fruit" : {"type" : "string", "minLength" : 1, "maxLength" : 10}, "quantity" : {"type" : "number", "minimum" : 0, "maximum" : 100}}, "required" : ["fruit", "quantity"] }') ); We can also use the VALIDATE keyword with an IS JSON condition in a query. Also we can use this feature when doing select : select * from t1 where json_data is json validate '{ "type" : "object", "properties" : {"fruit" : {"type" : "string", "minLength" : 1, "maxLength" : 10}, "quantity" : {"type" : "number", "minimum" : 0, "maximum" : 100}}, "required" : ["fruit", "quantity"] }'; Finaly above query only list standard and without syntax error records in result. DBMS_JSON_SCHEMA.IS_SCHEMA_VALID The IS_SCHEMA_VALID function in the DBMS_JSON_SCHEMA package can check the validity of a JSON schema de fi nition. In the following example we call it with a valid JSON schema, then an invalid one. Sql> select dbms_json_schema.is_schema_valid('{ "type" : "object", "properties" : {"fruit" : {"type" : "string", "minLength" : 1, "maxLength" : 10}, "quantity" : {"type" : "number", "minimum" : 0, "maximum" : 100}}, "required" : ["fruit", "quantity"] }') as is_valid; IS_VALID
  • 5. ---------- 1 SQL> select dbms_json_schema.is_schema_valid('banana') as is_valid; * ERROR at line 1: ORA-40441: JSON syntax error SQL> ----------------------- Regards, Alireza Kamrani Senior RDBMS Consultant.