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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • A Comprehensive Comparison of Serverless Databases and Dedicated Database Servers in the Cloud
  • Doris vs Elasticsearch: A Comparison and Practical Cost Case Study
  • Keep Calm and Column Wise
  • Accelerating Insights With Couchbase Columnar

Trending

  • How to Migrate From C/C++ to Rust: A Practical Guide for Embedded IoT Systems
  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption
  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • Build a Voice Assistant With Gemini Live API

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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.

By 
Emrah Mete
·
Updated Sep. 05, 18 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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.

Related

  • A Comprehensive Comparison of Serverless Databases and Dedicated Database Servers in the Cloud
  • Doris vs Elasticsearch: A Comparison and Practical Cost Case Study
  • Keep Calm and Column Wise
  • Accelerating Insights With Couchbase Columnar

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook