DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Data Engineering
  3. Databases
  4. A Comparison of JSON Values in a Database

A Comparison of JSON Values in a Database

In this article, I will talk about some of the new SQL functions that come with Oracle 18c and look at what we can do by trying a few different scenarios.

Emrah Mete user avatar by
Emrah Mete
CORE ·
Sep. 05, 18 · Analysis
Like (3)
Save
Tweet
Share
13.61K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will talk about some of the new SQL functions that come with Oracle 18c. I hope this article is useful in the sense of awareness. 

As we know, Oracle 18c was announced in February last year, and users are made available for use in Cloud environments. Following this announcement, Oracle has introduced a new version for its end users via the LiveSQL platform. 

I will perform the function tests that are the subject of this article through the LiveSQL platform.

The new SQL functions, which are the subject of the article, check the content of the JSON data we have stored in the database and understand if the JSONs match. With the existing infrastructure, it is necessary to develop complex SQL queries in order to be able to control the content of JSONs, and this control can be done very quickly and easily with newly developed functions.

Now let's look at what we can do by trying a few different scenarios. Let's start by creating a sample table and data.

CREATE TABLE comp_json_values
(
   json_val_1   VARCHAR2 (2000),
   json_val_2   VARCHAR2 (2000),
   use_case_desc VARCHAR2(2000)
);

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"key":"k1","value":"v1"}',
               'Exactly Same');

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"key":"k1" ,  "value":"v1"   }',
               'Exactly Same but having whitespaces');    

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"key":"k2","value":"v2"}',
               'Format:Same - Order:Same - Values:Different');

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"key":"k2","value":"v2","value2":"v3"}',
               'Format:Different - Order:Different - Values:Different');

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"value":"v1","key":"k1"}',
               'Format:Same - Order:Different - Values:Same');

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"value":"v21","key":"k21"}',
               'Format:Same - Order:Different - Values:Different');

INSERT INTO comp_json_values
     VALUES (
               '{"key":"k1","value":"v1"}',
               '{"value2":"v2","key2":"k2"}',
               'Format:Different - Order:Different - Values:Different');

COMMIT;

select * from comp_json_values;


Now let's check the JSON data with the functions that the new subroutine has to offer. In what scenario do we get the results?

SELECT json_val_1,
       json_val_2,
       use_case_desc,
       CASE
          WHEN json_equal (json_val_1, json_val_2) THEN 'Match'
          ELSE 'Mismatch'
       END
          json_comp
FROM comp_json_values;

We can use this in the CASE, WHEN, and WHERE clauses.

SELECT json_val_1, json_val_2, use_case_desc
  FROM comp_json_values
 WHERE json_equal (json_val_1, json_val_2);

select json_val_1, 
       json_val_2, 
       use_case_desc
from comp_json_values
where not json_equal(json_val_1,json_val_2);

The new functions that come with the new infrastructure can also be used in PL/SQL basically.

Thanks, and let me know your thoughts in the comments section. 

JSON Database Comparison (grammar)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Real-Time Analytics for IoT
  • Steel Threads Are a Technique That Will Make You a Better Engineer
  • Building a Real-Time App With Spring Boot, Cassandra, Pulsar, React, and Hilla
  • Spring Boot, Quarkus, or Micronaut?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: