JSON-Relational Duality Views in Oracle AI Database: The Best of Documents and Tables


Oracle AI Database 26ai introduces **JSON-Relational Duality Views** — a powerful feature that lets you access the exact same data as either relational tables **or** JSON documents, without any data duplication or complex synchronization.


It gives you the flexibility of documents and the power of relational databases at the same time.

Why Duality Views Matter

  • Developers love JSON documents for their simplicity and hierarchy
  • DBAs and analysts love relational tables for normalization, consistency, and analytics
  • Duality views let both teams work on the **same underlying data** using whichever model fits their needs

How Duality Views Work

A duality view is a declarative mapping between relational tables and JSON documents. The data is stored **relationally** (in tables), but you can read and write it as JSON documents — the database automatically handles the assembly and disassembly.

Changes made through the document view instantly appear in the tables, and vice versa.

Simple Example

-- 1. Create the underlying relational table
CREATE TABLE dept_tab (
    deptno    NUMBER(2,0) PRIMARY KEY,
    dname     VARCHAR2(14),
    code      NUMBER(13,0),
    state     VARCHAR2(15),
    country   VARCHAR2(15)
);

-- 2. Create the Duality View
CREATE JSON RELATIONAL DUALITY VIEW dept_dv AS
  SELECT JSON { '_id'      : d.deptno,
                'deptName' : d.dname,
                'location' : { 'zipcode' : d.code,
                               'country' : d.country }
    FROM dept_tab d
    WITH UPDATE INSERT DELETE;

This single view now supports a collection of JSON documents like this:

{
  "_id"      : 200,
  "deptName" : "HR",
  "location" : {
    "zipcode" : 94065,
    "country" : "USA"
  }
}

Key Benefits

  • Document-centric apps can use MongoDB API, ORDS, or SQL/JSON functions
  • Relational apps can query the underlying tables directly with SQL
  • No data duplication — everything stays normalized and consistent
  • Full updatability (INSERT, UPDATE, DELETE) on the document side
  • Multiple duality views can be built on the same tables for different use cases

Advanced Capabilities

  • Some columns can be left unmapped (not exposed in JSON)
  • You can store parts of the document as native JSON columns for maximum flexibility
  • Fields can be generated automatically or hidden for internal use
  • Views can be fully updatable, partially updatable, or read-only

Best Practices

  • Use duality views for applications that need both flexible documents and strong relational integrity
  • Start simple — map one or two tables first
  • Leverage JSON columns for complex nested structures that don’t need normalization
  • Combine with Oracle AI Vector Search, Private Agent Factory, or MCP Server for powerful AI use cases

Conclusion

JSON-Relational Duality Views eliminate the traditional trade-off between document and relational models. You get the best of both worlds in a single, high-performance, secure Oracle Database engine.

Whether you’re building modern microservices, AI-powered applications, or traditional enterprise systems, duality views give you maximum flexibility without compromising on data integrity or performance.

Post a Comment

Previous Post Next Post