OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    JSON_TABLE

    Last Updated:2026-04-14 12:43:57  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Syntax
    Examples

    folded

    Share

    Purpose

    The JSON_TABLE() function provides a way to link relational tables with JSON structured data. You can use the output of JSON_TABLE() in SQL like a virtual relational table. JSON_TABLE() provides column output for each JSON value and multi-row (column) output for arrays within JSON. JSON_TABLE() must be used in the FROM clause of a SELECT statement.

    Syntax

    JSON_TABLE(
            expr [FORMAT JSON]
            [, json_path_literal]
            [ERROR | NULL ON ERROR]
            COLUMNS (
              [column_name [json_value_return_type] EXISTS [PATH path_literal] [json_exists_on_error_clause] [json_exists_on_emtpy_clause]]
              [column_name [json_query_return_type] FORMAT JSON [ALLOW|DISALLOW SCALARS] [json_query_wrapper_clause] [PATH path_literal] [json_query_on_error_clause]]
              [column_name [json_value_return_type] [TRUNCATE] [PATH path_literal] [json_exists_on_error_clause] [json_exists_on_emtpy_clause]]
              [column_name FOR ORDINALITY]
              [NESTED PATH path_literal COLUMNS (
                # Nested structure, repeating the parent level syntax
                ...
              )]
            )
           )
    

    Syntax

    The syntax of the JSON_TABLE() function is described as follows:

    • json_value_return_type: Same as the RETURNING clause of JSON_VALUE().
    • json_query_return_type: Same as the RETURNING clause of JSON_QUERY().
    • FORMAT JSON: Optional. This clause is required when the data type of expr is BLOB.
    • path_literal: A general JSON path string.
    • json_exists_on_emtpy_clause: Same as the emtpy clause of JSON_EXISTS().
    • json_exists_on_error_clause: Same as the error clause of JSON_EXISTS().
    • json_query_on_error_clause: Same as the error clause of JSON_QUERY().
    • json_query_wrapper_clause: Same as the WRAPPER clause of JSON_QUERY().
    • The FOR ORDINALITY clause provides a row number for the current output row, which is an INT column. The output value types have four types. Except for the ORDINALITY column, the other three are similar to the functionality and behavior of JSON_VALUE(), JSON_QUERY(), and JSON_EXISTS().
    • The [NESTED PATH ...] clause is a repeated nested structure.
    • ERROR clause: Specifies the error handling for the initial input expr.

    Examples

    # Use the NESTED COLUMN clause.
    DROP TABLE jsonb_table_test;
    CREATE TABLE jsonb_table_test (js VARCHAR2 (4000));
    
    DELETE FROM jsonb_table_test;
    INSERT INTO jsonb_table_test VALUES (
      '[
      	{"c": [7], "d": [3], "a": 2,  "b": [3,4]}
      ]'
    );
    
    obclient> SELECT jt.* FROM jsonb_table_test jtt,
          json_table (jtt.js, '$[*]'
              columns (
                nested path '$.c[*]' COLUMNS (c int path '$'),
                nested path '$.d[*]' COLUMNS (d int path '$'),
                nested path '$.b[*]' COLUMNS (b int path '$'),
                a int path '$.a'
              )
          ) jt;
    +------+------+------+------+
    | C    | D    | B    | A    |
    +------+------+------+------+
    | NULL | NULL |    3 |    2 |
    | NULL | NULL |    4 |    2 |
    | NULL |    3 | NULL |    2 |
    |    7 | NULL | NULL |    2 |
    +------+------+------+------+
    4 rows in set
    
    # Use the NESTED COLUMN clause and the ORDINALITY column.
    obclient> INSERT INTO jsonb_table_test VALUES (
            '[
            {"a":  1,  "b": [], "c": []},
            {"a":  2,  "b": [1, 2, 3], "c": [10, null, 20]},
            {"a":  3,  "b": [1, 2], "c": []},
            {"a":  4, "b": [1, 2], "c": [123]}
            ]'
          );
    Query OK, 1 row affected
    
    obclient> SELECT jt.* FROM jsonb_table_test jtt,
            json_table (jtt.js, '$[*]'
              columns (
                nested path '$.c[*]' COLUMNS (c int path '$'),
                nested path '$.b[*]' COLUMNS (b int path '$'),
                n FOR ORDINALITY,
                a int path '$.a'
              )
            ) jt;
    +------+------+------+------+
    | C    | B    | N    | A    |
    +------+------+------+------+
    | NULL | NULL |    1 |    1 |
    | NULL |    1 |    2 |    2 |
    | NULL |    2 |    2 |    2 |
    | NULL |    3 |    2 |    2 |
    |   10 | NULL |    2 |    2 |
    | NULL | NULL |    2 |    2 |
    |   20 | NULL |    2 |    2 |
    | NULL |    1 |    3 |    3 |
    | NULL |    2 |    3 |    3 |
    | NULL |    1 |    4 |    4 |
    | NULL |    2 |    4 |    4 |
    |  123 | NULL |    4 |    4 |
    +------+------+------+------+
    12 rows in set
    
    # Query the json_value column of json_table and use the EMPTY clause.
    obclient> SELECT jt.* FROM json_table (
            '{"data": 123.45}',
            '$'
             columns (a CLOB path '$.nokey' default 'abc' on EMPTY)
            ) jt;
    +------+
    | A    |
    +------+
    | abc  |
    +------+
    1 row in set
    
    # Query the json_value column of json_table and use the EMPTY clause.
    obclient> SELECT jt.* FROM json_table (
            '{"data": 123.45}',
            '$'
             columns (a CLOB path '$.nokey' NULL on EMPTY)
            ) jt;
    +------+
    | A    |
    +------+
    | NULL |
    +------+
    1 row in set
    
    obclient> SELECT jt.* FROM
       json_table(
       '{"details":
         [ {"branch_code": "3020300", "products": [
                                               "23D0980000000000",
                                               "23E2980000000000",
                                               "23E3980000000004"]},
          {"branch_code": "3090100", "products": [
                                               "23D0980000000000",
                                               "23E2980000000000"]}],
          "extras": ["AWUX1201293111", "AWUX1201293112"]
         }',
         '$.details[*]'
         columns (
           branch_code varchar2(100) path '$.branch_code',
           nested path '$.products[*]' columns (product varchar2(100) path '$[*]')
           )
         ) jt;
    
    +-------------+------------------+
    | BRANCH_CODE | PRODUCT          |
    +-------------+------------------+
    | 3020300     | 23D0980000000000 |
    | 3020300     | 23E2980000000000 |
    | 3020300     | 23E3980000000004 |
    | 3090100     | 23D0980000000000 |
    | 3090100     | 23E2980000000000 |
    +-------------+------------------+
    5 rows in set
    
    # Query the JSON_EXISTS column of the json_table function.
     obclient> SELECT jt.* FROM json_table (
            '{
              "a": "1997-8-14 11:11:11",
              "b" : 123,
              "c": "varchar2"
             }',
            '$' columns (
                a date EXISTS path '$.a',
                b int EXISTS path '$.b' ERROR ON EMPTY,
                c varchar2(32) format json path '$.c' NULL ON EMPTY
              )
            ) jt;
    +---------------------+------+----------+
    | A                   | B    | C        |
    +---------------------+------+----------+
    | 1997-08-14 11:11:11 |  123 | varchar2 |
    +---------------------+------+----------+
    1 row in set
    
    # Query the json_query column of the json_table function.
    obclient> SELECT jt.* FROM json_table (
            '{"data": [1, 2, 3, 3]}',
            '$'
             columns (a varchar2(1024) FORMAT JSON path '$.data[*]')
            ) jt;
    +--------------+
    | A            |
    +--------------+
    | [1, 2, 3, 3] |
    +--------------+
    1 row in set
    

    Previous topic

    JSON_EXISTS
    Last

    Next topic

    JSON_EQUAL
    Next
    What is on this page
    Purpose
    Syntax
    Syntax
    Examples