Recently, I got opportunity to work on JSON data in Oracle Database. We were receiving this JSON data from Cisco Webex APIs, and the JSON data was complex (nested with json array). With this blog, I am sharing simple example how to parse complex JSON data in Oracle Database using SQL.
For this example, I am using SCOTT schema, and my current database version is Oracle 12.1 which was release in July 2013. With Current versions of Oracle 18c and 19c and Oracle Autonomous Databases, there has been lot of enhancements to parse JSON data. Anyways, let us first create DEPT_JSON table, which will have JSON_VALUE column of CLOB type. One JSON_VALUE field will store complete information of a department and employees data of that department in JSON format.
For this example, I am using SCOTT schema, and my current database version is Oracle 12.1 which was release in July 2013. With Current versions of Oracle 18c and 19c and Oracle Autonomous Databases, there has been lot of enhancements to parse JSON data. Anyways, let us first create DEPT_JSON table, which will have JSON_VALUE column of CLOB type. One JSON_VALUE field will store complete information of a department and employees data of that department in JSON format.
ngarg> CREATE TABLE DEPT_JSON
2 (
3 ID NUMBER,
4 JSON_VALUE clob
5 );
Table created.
ngarg> INSERT INTO DEPT_JSON
2 VALUES(10,
3 '{"DEPTNO": "10",
4 "DNAME": "ACCOUNTING",
5 "EMPLOYEES" : [{ EMPNO: 7839, "ENAME": "KING", SAL: 5000, "JOB": "PRESIDENT"},
6 { EMPNO: 7782, "ENAME": "CLARK", SAL: 2450, "JOB": "MANAGER"},
7 { EMPNO: 7934, "ENAME": "MILLER", SAL: 1300, "JOB": "CLERK"}
8 ]
9 }'
10 );
1 row created.
ngarg> INSERT INTO DEPT_JSON
2 VALUES(20,
3 '{"DEPTNO": "20",
4 "DNAME": "RESEARCH",
5 "EMPLOYEES" : [{ EMPNO: 7566, "ENAME": "JONES", SAL: 2975, "JOB": "MANAGER"},
6 { EMPNO: 7788, "ENAME": "SCOTT", SAL: 3000, "JOB": "ANALYST"},
7 { EMPNO: 7902, "ENAME": "FORD", SAL: 3000, "JOB": "ANALYST"},
8 { EMPNO: 7369, "ENAME": "SMITH", SAL: 800, "JOB": "CLERK"},
9 { EMPNO: 7876, "ENAME": "ADAMS", SAL: 1100, "JOB": "CLERK"}
10 ]
11 }'
12 );
1 row created.
ngarg> INSERT INTO DEPT_JSON
2 VALUES(30,
3 '{"DEPTNO": "30",
4 "DNAME": "RESEARCH",
5 "EMPLOYEES" : [{ EMPNO: 7698, "ENAME": "BLAKE", SAL: 2850, "JOB": "MANAGER"},
6 { EMPNO: 7499, "ENAME": "ALLEN", SAL: 1600, "JOB": "SALESMAN"},
7 { EMPNO: 7521, "ENAME": "WARD", SAL: 1250, "JOB": "SALESMAN"},
8 { EMPNO: 7654, "ENAME": "MARTIN", SAL: 1250, "JOB": "SALESMAN"},
9 { EMPNO: 7844, "ENAME": "TURNER", SAL: 1500, "JOB": "SALESMAN"},
10 { EMPNO: 7900, "ENAME": "JAMES", SAL: 950, "JOB": "CLERK"}
11 ]
12 }'
13 );
1 row created.
ngarg> commit;
Commit complete.
As you would have noticed, I have not specified any different data type to store JSON, JSON is simply being stored in CLOB field. Now we can use following SQL to parse Nested JSON data along with JSON Array in Oracle Database by using JSON_TABLE function.
ngarg> SELECT
2 DEPTNO, DNAME, EMPNO, ENAME, JOB, SAL
3 FROM
4 DEPT_JSON D,
5 JSON_TABLE
6 (
7 D.JSON_VALUE, '$' COLUMNS
8 (
9 DEPTNO NUMBER(4) PATH '$.DEPTNO',
10 DNAME VARCHAR2(15) PATH '$.DNAME',
11 NESTED path '$.EMPLOYEES[*]' COLUMNS
12 (
13 EMPNO NUMBER(5) PATH '$.EMPNO',
14 ENAME VARCHAR2(15) PATH '$.ENAME',
15 JOB VARCHAR2(15) PATH '$.JOB',
16 SAL NUMBER(7,2) PATH '$.SAL'
17 )
18 )
19 ) J
20 ORDER BY DEPTNO;
DEPTNO DNAME EMPNO ENAME JOB SAL
---------- --------------- ---------- --------------- --------------- ----------
10 ACCOUNTING 7839 KING PRESIDENT 5000
10 ACCOUNTING 7934 MILLER CLERK 1300
10 ACCOUNTING 7782 CLARK MANAGER 2450
20 RESEARCH 7369 SMITH CLERK 800
20 RESEARCH 7788 SCOTT ANALYST 3000
20 RESEARCH 7566 JONES MANAGER 2975
20 RESEARCH 7902 FORD ANALYST 3000
20 RESEARCH 7876 ADAMS CLERK 1100
30 RESEARCH 7698 BLAKE MANAGER 2850
30 RESEARCH 7499 ALLEN SALESMAN 1600
30 RESEARCH 7521 WARD SALESMAN 1250
30 RESEARCH 7900 JAMES CLERK 950
30 RESEARCH 7844 TURNER SALESMAN 1500
30 RESEARCH 7654 MARTIN SALESMAN 1250
14 rows selected.
JSON_TABLE can be used in Oracle Database to specify the structure of JSON data, and convert JSON data into relational. As you can see, JSON_TABLE is easy to use. We simply need to define the PATH of each value in JSON and if data is nested we can use NESTED PATH, and Oracle database will automatically convert single JSON data with nested JSON into multiple relational rows. At the end of this post, I would also like to recommend to read JSON in Oracle Database with Examples to understand the how can we simply use dot (.) notation in SQL to read JSON Data in Oracle database
Related Posts
- JSON in Oracle Database with Examples
- Convert XML to Rows and Columns in Oracle
- Generate XML data using SQL in Oracle Database
- Load XML File in Oracle Table
- XML output from SQL query
- Create CSV file using PL/SQL
- Load CSV file in Oracle using PL/SQL
- SQL*Loader - Load Excel/CSV file into Oracle Database Table
- SQLFormat - CSV, JSON, XML - Format output of SQL in SQLDeveloper
Your topic is very good and useful for us ... Thank you for sharing your information. Acronis Cyber Protect
ReplyDeleteAcronis Cyber Protection
Data Recovery Software
Disaster Recovery Services
>It is very good and useful .Learned a lot of new things from your post!Good creation ,thanks for good info oracle training in chennai
ReplyDeletegood info provided here oracle training in chennai
ReplyDeleteExcellent Post.
ReplyDeleteAWS Training in Chennai | Best AWS Training Institute in Chennai | AWS Training Institute in Chennai | AWS Training Center in Chennai
Thanks for sharing such a great post.
ReplyDeleteHindustan Tradecom is the best Share broker in Jaipur, jodhpur, Bikaner, Kota, Rajasthan and leading equity trader in Jaipur, Rajasthan. If you want to Open demat account in Jaipur or Open trading account in Jaipur or looking for commodity broker in Jaipur then Hindustan Tradecom is the right place for you to consult.
Thank you for sharing such a great information with us .
ReplyDeleteIndia’s No. 1 Bulk SMS Platform
This comment has been removed by the author.
ReplyDeleteThanks for this lovely article. You can see the difference between SQL and PLSQL also in simple words .
ReplyDeleteLink for the same :
https://www.complexsql.com/difference-between-sql-and-pl-sql/
Hope you will most more comments like this.
This comment has been removed by the author.
ReplyDeleteWow, what a nice blog. I have read it and really impressed by its writing.
ReplyDeleteMeerahini is the best site to buy Jaipur Salwar Suits Online and Hand block Kurta sets. We have straight suit sets, anarkali suit sets, kurta and plazzo sets, and Sharara Sets. We have premium clothing collection of Rang and Utsav.a
GCL is one of India's leading financial services group with decades of experience in the financial market. lEARN More: best stock trading companies in jaipur
ReplyDeleteInfycle Technologies, the best software training institute in Chennai offers the No.1 Python Certification in Chennai for tech professionals. Apart from the Python Course, other courses such as Oracle, Java, Hadoop, Selenium, Android, and iOS Development, Big Data will also be trained with 100% hands-on training. After the completion of training, the students will be sent for placement interviews in the core MNC's. Dial 7502633633 to get more info and a free demo.
ReplyDeleteThanks for sharing wonderful Information. In this article I learn a lot. And if you want to know m about wedding or matrimonial services visit:- Truelymarry
ReplyDeleteOne of the best Indian matrimonial site in Kanpur TruelyMarry
We provide services:-Kanpur , Manglik , Second Marriage
Good one this is one of the very good blog. It has increased my knowledge
ReplyDeleteAlteza is one of the best Web and App developer company. Located in India
visit us:- http://altezatel.com/
Thanks for the marvelous posting! I actually enjoyed reading it, you will be a great author. I want to encourage continue your great writing. Thanks for sharing your nice topic.
ReplyDeleteTelemedicine App Development
Great information, I found some interesting information from your website.
ReplyDeleteAluminum windows in Chennai
Best Aluminium Windows in Chennai
Best UPVC Windows in
Chennai
Hi, I am John Smith I am Web Developer, It is an amazing blog thanks for the sharing the blog. Frantic infotech provide the ios ui ux app development company such as an information about software development for costumer service. Frantic infotech also provide the react native mobile app development. Theve delopment of advanced web applications is Orient Software’s specialty and we will successfully fulfill all your web application development requirements, from small-sized to wider-ranged projects.
ReplyDeleteVery helpful blog! Thnak you for sharing.
ReplyDeleteAlteza is a leading online pharmacy app development company and we address every concern of our clients by providing comprehensive online pharmacy apps for their business needs.
Wecadenceindia is a Best Digital Marketing Agency In Noida. For any kind of digital marketing service contact them.
ReplyDeleteThe great website and information shared are also very appreciable. Spiderman Hoodie
ReplyDeleteYou have my sincere gratitude for giving me access to this fantastic material. I have gained a lot of knowledge from your content.
ReplyDeletepopular tractor price
Comparison Charts are best to use when you are looking for something specific, say in case you need to buy something, this chart will help you look at their advantages, disadvantages, prices, reviews, features, etc. Thus, making it easier to choose between them easily. Read more here :함평아로마
ReplyDelete영광아로마
장성아로마
신안아로마
완주아로마
진안아로마
무주아로마
장수아로마
Your writing is impressive, and your helpful advice is greatly appreciated.
ReplyDelete4x4 tractor price
Web designing, Web configuration, Web content turn of events, customer contact, customer side/worker side scripting, Web worker and organization security arrangement, and web based business improvement. Programming advancement is the way toward considering, indicating, planning, programming, archiving, testing, and bug fixing associated with making and looking after applications, structures, or other programming segments.Software Company in Agra Programming improvement is an interaction of composing and keeping up the source code, yet from a more extensive perspective, it incorporates all that is included between the origination of the ideal programming through to the last sign of the product, now and again in an arranged and organized cycle. Subsequently, programming improvement may incorporate exploration, new turn of events, prototyping, alteration, reuse, re-designing, support, or whatever other exercises that bring about programming items
ReplyDeleteThanks for the sharing.its interesting.
ReplyDeletesoftware application development company
very informative collection you have thank for sharing with us. silent readers
ReplyDeleteIf you are looking for personal trainer delhi then please contact us for more details.
ReplyDeleteIf you are looking for indian email service then Mailing solution is a popular bulk email service provider that offers a range of features, including email automation, landing pages, and web push notifications.
ReplyDeleteuşak
ReplyDeletevan
hakkari
elazığ
bingöl
TC3
kastamonu evden eve nakliyat
ReplyDeleteantep evden eve nakliyat
balıkesir evden eve nakliyat
erzincan evden eve nakliyat
ankara evden eve nakliyat
H216A
kırşehir evden eve nakliyat
ReplyDeletegiresun evden eve nakliyat
tekirdağ evden eve nakliyat
ardahan evden eve nakliyat
izmir evden eve nakliyat
BYO
6990D
ReplyDeleteKırklareli Evden Eve Nakliyat
Muş Lojistik
Tokat Evden Eve Nakliyat
İzmir Evden Eve Nakliyat
Hatay Lojistik
3D7F5
ReplyDeleteEdirne Lojistik
Kütahya Evden Eve Nakliyat
Osmaniye Lojistik
Adıyaman Evden Eve Nakliyat
Çanakkale Parça Eşya Taşıma
0EE55
ReplyDeleteKeçiören Boya Ustası
Manisa Şehir İçi Nakliyat
Ağrı Şehirler Arası Nakliyat
Aydın Parça Eşya Taşıma
Mamak Boya Ustası
Kars Parça Eşya Taşıma
Tokat Evden Eve Nakliyat
Ünye Çelik Kapı
Osmaniye Evden Eve Nakliyat
CAD62
ReplyDeleteKırklareli Lojistik
Edirne Parça Eşya Taşıma
Ankara Parke Ustası
Tunceli Parça Eşya Taşıma
Diyarbakır Lojistik
Ağrı Şehirler Arası Nakliyat
Ardahan Şehirler Arası Nakliyat
Aksaray Şehir İçi Nakliyat
Bursa Şehir İçi Nakliyat
BF689
ReplyDeleteSamsun Lojistik
Ordu Evden Eve Nakliyat
Batman Lojistik
Ünye Boya Ustası
Afyon Şehir İçi Nakliyat
Siirt Parça Eşya Taşıma
Sivas Lojistik
Bybit Güvenilir mi
Antep Lojistik
HACK ATM AND BECOME TODAY RICH You can hack and crash into it without having too much weap남원출장샵ons or weapons. How is that possible?
ReplyDeleteB2750
ReplyDeleterastgele sohbet
sohbet siteleri
kilis görüntülü sohbet ücretsiz
afyon sesli sohbet mobil
yabancı görüntülü sohbet siteleri
sivas en iyi ücretsiz sohbet uygulamaları
ankara canlı sohbet ücretsiz
bingöl ücretsiz sohbet sitesi
isparta rastgele sohbet
B02D0
ReplyDeleteelazığ mobil sohbet sitesi
Antep Sohbet Muhabbet
maraş parasız sohbet siteleri
Antep Canlı Sohbet Ücretsiz
Osmaniye Canlı Ücretsiz Sohbet
erzincan canlı sohbet odaları
canli sohbet chat
adıyaman sohbet chat
mobil sohbet chat
8E34A
ReplyDeletebilecik mobil sesli sohbet
Kırşehir Ücretsiz Görüntülü Sohbet
isparta muhabbet sohbet
ardahan kadınlarla sohbet et
sinop canlı sohbet odası
siirt random görüntülü sohbet
aydın sohbet odaları
kocaeli canlı görüntülü sohbet odaları
Izmir Bedava Sohbet Siteleri
3FBE7
ReplyDeleteBinance Referans Kodu
Ön Satış Coin Nasıl Alınır
Flare Coin Hangi Borsada
Kripto Para Kazma Siteleri
Mefa Coin Hangi Borsada
Bonk Coin Hangi Borsada
Binance Borsası Güvenilir mi
Coin Nasıl Çıkarılır
Görüntülü Sohbet
00329
ReplyDeleteLoop Network Coin Hangi Borsada
Twitter Retweet Satın Al
Kripto Para Nasıl Çıkarılır
Binance Referans Kodu
Bitcoin Para Kazanma
Telegram Abone Hilesi
Alyattes Coin Hangi Borsada
Binance Hesap Açma
Coin Nedir
F98DC
ReplyDeleteBitcoin Madenciliği Nasıl Yapılır
Omlira Coin Hangi Borsada
Periscope Beğeni Satın Al
Coin Kazanma
Binance Yaş Sınırı
Kripto Para Kazma
Kripto Para Nasıl Kazılır
Pinterest Takipçi Hilesi
Soundcloud Reposts Hilesi
82 pg สล็อต ออนไลน์ เพียงแค่คุณมีอินเทอร์เน็ตและอุปกรณ์ที่เชื่อมต่ออย่างเรียบร้อย สามารถเข้าสู่เว็บไซต์หรือแอปพลิเคชันของ pg slot ได้ทันทีสมัครสมาชิกได้อย่างรวดเร็วมาก
ReplyDeleteAmazing blog and gives a lot of idea about Oracle, there are various things that are not known oracle are cleared in this blog. We have several other blogs to read
ReplyDeleteHealthcare software development blog
Telemedicine app development
EHR software development
Healthcare software development company
Thanks for sharing. Great blog! I finally found something that helped me. Keep up the amazing work. Check our new rhiannon fish measurements coat .
ReplyDelete