Skip to main content

JSON-Relational Duality Views in Oracle APEX

Oracle 23ai Deep Dive

JSON-Relational Duality Views
in Oracle APEX

The complete guide to bridging relational tables and JSON documents storing data efficiently, accessing it flexibly.

1What Are Duality Views?

In one of my Oracle APEX projects, I had a requirement to expose relational data as JSON for integration with external systems. The application needed to support both database transactions and API-based data exchange, which made the design slightly complex. Initially, I considered building REST APIs with manual JSON construction using SQL functions. However, maintaining that logic became difficult as the data model evolved. That’s when I explored JSON-Relational Duality Views — a feature that allows working with relational data and JSON seamlessly.

๐Ÿ’ก
Key insight: A JSON Relational Duality View is a database view with a single JSON column named data that you can use to read and write information from one or more underlying relational tables — simultaneously.

2Why We Needed Duality Views

In my experience, I often faced confusion about how to store and use data — whether to keep it in relational tables or convert it into JSON for modern applications. Relational tables are good for maintaining data properly, but when it comes to APIs or frontend usage, JSON format is much easier to work with. Earlier, I had to handle both separately — storing data in tables and then writing extra logic to convert it into JSON. This made the process more complex and time-consuming. With Duality Views, this problem got solved for me. I can now work with the same data in both relational and JSON formats without writing additional conversion logic.

ApproachStorageApp AccessProblem
Pure RelationalNormalized tablesSQL JOINsComplex JOINs; hard for modern APIs
Pure NoSQL / JSONJSON documentsDocument APIData duplication, no normalization
✅ Duality ViewsRelational tablesJSON documentsBest of both — zero trade-offs

3Prerequisites

⚠️
Important: Duality Views require Oracle Database 23ai or later. They are not available in 19c or 21c. For Oracle APEX, you need APEX 23+, ideally APEX 24.2 for the full feature set.

In Oracle APEX, a Duality View Source consists of:

  • The owner and name of the Duality View object in Oracle Database
  • A Data Profile — automatically built by APEX after reading the JSON schema from the view
  • The Data Profile maps JSON attributes to typed columns that APEX components can consume directly

4Practical Example: Employee-Department App

Let's walk through a complete real-world example — an Employee Directory that exposes nested department data as clean JSON documents, while storing everything in two normalized tables.

Step 1 — Create the Relational Tables

Start with plain, standard Oracle tables. Nothing special needed here:

SQL — Table Creation
-- Department master table
CREATE TABLE dept (
  deptno   NUMBER PRIMARY KEY,
  dname    VARCHAR2(50),
  loc      VARCHAR2(50)
);

-- Employee table with FK to dept
CREATE TABLE emp (
  empno    NUMBER PRIMARY KEY,
  ename    VARCHAR2(50),
  job      VARCHAR2(30),
  sal      NUMBER,
  deptno   NUMBER REFERENCES dept(deptno)
);

-- Sample data
INSERT INTO dept VALUES (10, 'ACCOUNTING', 'CHENNAI');
INSERT INTO dept VALUES (20, 'RESEARCH',   'BANGALORE');
INSERT INTO emp  VALUES (101, 'Ravi',  'ANALYST',   75000, 20);
INSERT INTO emp  VALUES (102, 'Priya', 'MANAGER',   90000, 10);
INSERT INTO emp  VALUES (103, 'Arjun', 'DEVELOPER', 65000, 20);
COMMIT;

Step 2 — Create the Duality View

Create the Duality View that exposes each employee as a nested JSON document with department info — from two tables, in one view:

SQL — Duality View Definition
CREATE OR REPLACE JSON RELATIONAL DUALITY VIEW emp_dept_dv AS
  SELECT JSON {
    '_id'        : e.empno,
    'name'       : e.ename,
    'job'        : e.job,
    'salary'     : e.sal,
    'department' : (
      SELECT JSON {
        'deptno' : d.deptno,
        'dname'  : d.dname,
        'loc'    : d.loc
      }
      FROM dept d WITH NOINSERT NOUPDATE NODELETE
      WHERE d.deptno = e.deptno
    )
  }
  FROM emp e WITH INSERT UPDATE DELETE;
Notice: WITH INSERT UPDATE DELETE on emp allows full CRUD. WITH NOINSERT NOUPDATE NODELETE on dept makes it read-only through this view. Fine-grained table-level control!

Step 3 — Query It Like JSON

SQL — Querying the Duality View
-- Read all employees as JSON documents
SELECT * FROM emp_dept_dv;

-- Find a specific employee
SELECT e.data FROM emp_dept_dv e
WHERE e.data.name.string() = 'Ravi';

The output is a beautifully structured JSON document:

{
  "_id": 101,
  "name": "Ravi",
  "job": "ANALYST",
  "salary": 75000,
  "department": {
    "deptno": 20,
    "dname": "RESEARCH",
    "loc": "BANGALORE"
  }
}

Two relational tables. One clean JSON document. Zero manual serialization code. That is the power of Duality Views.

5Configuring Duality Views in Oracle APEX

After creating the Duality View in the database, connecting it to your APEX application takes just a few clicks:

Step 1
Open your Oracle APEX application workspace
Step 2
Go to Shared Components → Data Sources → Duality Views
Step 3
Click Create — enter a name and select the DB schema
Step 4
Pick your Duality View object from the list
Step 5
APEX auto-reads the JSON schema and builds a Data Profile automatically
Step 6
Use in Reports, Forms, Charts, LOVs, and Automations — immediately!

6CRUD Operations via Duality Views

Duality Views support full Create, Read, Update, and Delete using JSON. Every operation automatically maps to the correct underlying relational tables — no separate DML per table needed.

INSERT — Add a New Employee

SQL — Insert
INSERT INTO emp_dept_dv VALUES (
  '{"_id":104,"name":"Meena","job":"DBA",
    "salary":80000,"department":{"deptno":10}}'
);
-- Oracle automatically inserts into the EMP table

UPDATE — Modify Salary

SQL — Update
UPDATE emp_dept_dv e
SET e.data = JSON_TRANSFORM(e.data, SET '$.salary' = 85000)
WHERE e.data._id = 104;
-- Updates SAL column in EMP table automatically

DELETE — Remove an Employee

SQL — Delete
DELETE FROM emp_dept_dv e
WHERE e.data._id = 104;
-- Deletes from EMP table. DEPT table untouched (NODELETE).
๐Ÿš€
Zero extra code: All CRUD operations automatically update the correct underlying tables. You never write separate DML for each table — the Duality View handles all the mapping.

7Key Benefits Summary

๐Ÿ—ƒ️
Normalized StorageNo data duplication. Full ACID compliance across all tables.
๐Ÿ“„
JSON AccessWorks seamlessly with modern REST APIs and frontend frameworks.
Auto CRUDWrite to the view — Oracle maps changes to the correct tables.
๐Ÿ—️
APEX IntegrationDirectly usable in Reports, Forms, Charts, LOVs, and Automations.
๐Ÿ”
ETags Built-inOptimistic concurrency control out of the box — no lock contention.
๐Ÿงน
No Temp TablesNo staging tables or collection parsing. Clean and direct.

๐Ÿ”ต For DBAs

Data stays perfectly normalized. No schema changes to existing tables. Full SQL analytics still work.

๐ŸŸข For Developers

Work with clean JSON documents. No ORM configuration. One API call fetches a complete nested object.

๐ŸŸก For Architects

One database. One source of truth. Support legacy SQL apps and modern JSON APIs simultaneously.

๐ŸŸฃ For APEX Devs

Configure as a Shared Component data source. Build reports and forms with zero PL/SQL boilerplate.

The Future of Oracle App Development is Dual

JSON-Relational Duality Views are not just a feature — they are a fundamental shift in how Oracle applications are built. Store once, access everywhere, in any format your application needs.

#OracleAPEX #Oracle23ai #DualityViews #JSONRelational #LowCode #DatabaseDev #ModernApps

Comments

Popular posts from this blog

Generate Custom PDFs in Oracle APEX with jsPDF

Generate Custom PDFs in Oracle APEX with jsPDF A complete step-by-step guide to building a client-side PDF generator with profile image embedding and PL/SQL database persistence. 📄 Step-by-step guide Oracle APEX jsPDF Dynamic Actions PL/SQL JavaScript "Picture this: your Oracle APEX application is polished, your users love it — but when they ask for a downloadable report with a profile picture and custom styling, you realize vanilla APEX isn't built for that out of the box. What if a single JavaScript library and one Dynamic Action could change everything?" Welcome to the world of jsPDF inside Oracle APEX . In this tutorial, we wire up a PDF generator that captures a user's name, email, phone number, and profile picture — renders them into a beautiful PDF layout — and saves everything to Oracle, all in one button click. ⓘ What you'll build: A dynamic PDF generat...

APEX Custom Auth Settings, Decoded!

Oracle APEX Security PL/SQL APEX Custom Auth Settings, Decoded Why I Build this I was building an internal APEX app — strictly for people on our corporate network. The default authentication worked, but it had a few things that kept bothering me. Anyone with valid credentials could log in from anywhere. Sessions expired with a useless error page. There was no audit trail — no way to know who logged in, when, or from where. And passwords were stored in plain text, which I just couldn't leave alone. So I did what any developer does — I built it myself. Custom authentication, from scratch, in PL/SQL. Turned out to be one of the best learning experiences I've had with APEX. Here's exactly how I did it. Img 1 : Head to Shared Components → Authentication Schemes → Create, choose Custom as the Scheme Type, and plug in your function and procedure names. Quick note before we get into the code — the s...

Record, Preview, Save — Video Recording in Oracle APEX

Oracle APEX · Video Recording Record Video Directly in Oracle APEX ๐ŸŽฌ Have you ever wished your users could say it instead of type it? In many modern applications, we've seen the ability to record a short video clip directly in the browser — no file uploads, no external tools. Just hit record, watch it back, and decide — save it or try again. Today, we're bringing that same experience into Oracle APEX: record, pause/resume, preview, save to DB, or retry. Let's build it. 1 Step 1 : Start by creating a Static Content Region on your APEX page. This will act as the container for our entire video recorder UI.Paste the provided HTML code into the region source. This gives you two video panels — one for the live camera preview and one for the recorded playback — along with your action buttons: Start, Pause, Resume, Stop, Save, and Retry. Copy <!-- Recorder UI --> < div id= "recorderUI...