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.2.5

    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.2.5
    iconOceanBase Database
    SQL - V 4.2.5
    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_QUERY

    Last Updated:2026-04-27 03:14:13  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Syntax
    Examples

    folded

    Share

    Purpose

    The JSON_QUERY() function is used to query one or more values from JSON data and returns these values.

    Syntax

    JSON_QUERY(
                  expr [FORMAT JSON],
                  json_path_literal
                      [RETURNING  CLOB|BLOB|JSON|VARCHAR2|VARCHAR2[size],]
                  [ALLOW|DISALLOW SCALARS]
                  [PRETTY]
                  [ASCII]
                  [WITHOUT [ARRAY] WRAPPER, WITH CONDITIONAL|UNCONDITIONAL [ARRAY] WRAPPER]
                  [ERROR|NULL|EMPTY|EMTPY ARRAY|EMPTY OBJECT ON ERROR]
                  [ERROR|NULL|EMPTY|EMTPY ARRAY|EMPTY OBJECT ON EMPTY]);
    

    Syntax

    The syntax of the JSON_QUERY() function is as follows:

    • [RETURNING CLOB | BLOB | JSON | VARCHAR2 | VARCHAR2[size]: Specifies the return value type. VARCHAR2[size] can be used to limit the length of the returned value. The default return type depends on the input data type. If the input is JSON, the output type is also JSON. If the input type is VARCHAR, the default output type is VARCHAR.

    • FORMAT JSON: Optional. This clause is required when the data type of expr is BLOB.

    • json_path_literal: Specifies the query path.

    • PRETTY: Specifies whether to use pretty-print when returning a character type.

    • ASCII: Automatically escapes any non-ASCII Unicode characters in the returned string using standard ASCII Unicode escape sequences.

    • WITHOUT WRAPPER: Disables the ARRAY WRAPPER feature.

    • WITH WRAPPER: Enables the ARRAY WRAPPER feature.

    • WITH UNCONDITIONAL WRAPPER: Equivalent to WITH WRAPPER.

    • WITH CONDITIONAL WRAPPER: Uses the ARRAY WRAPPER feature when returning multiple values. If a single value is returned, the ARRAY WRAPPER feature is ignored.

    • ERROR clause:

      • NULL ON ERROR: Returns NULL when an error occurs. This is the default setting.
      • ERROR ON ERROR: Returns the corresponding Oracle error when an error occurs.
      • EMPTY ON ERROR: Equivalent to specifying EMPTY ARRAY ON ERROR.
      • EMPTY ARRAY ON ERROR: Returns an empty JSON array when an error occurs.
      • EMPTY OBJECT ON ERROR: Returns an empty JSON object when an error occurs.
    • EMPTY clause:

      • NULL ON EMPTY: Returns NULL when no match is found. This is the default setting.
      • ERROR ON EMPTY: Returns the corresponding Oracle error when no match is found.
      • EMPTY ON EMPTY: Equivalent to specifying EMPTY ARRAY ON EMPTY.
      • EMPTY ARRAY ON EMPTY: Returns an empty JSON array when no match is found.
      • EMPTY OBJECT ON EMPTY: Returns an empty JSON object when no match is found.

    Examples

    # Use the RETURNING clause.
    obclient> SELECT JSON_QUERY('{"a":100, "b":200, "c":300}', '$') AS value FROM DUAL;
    +--------------------------------+
    | VALUE                          |
    +--------------------------------+
    | {"a": 100, "b": 200, "c": 300} |
    +--------------------------------+
    1 row in set
    
    obclient>SELECT JSON_QUERY('{"a":100, "b":200, "c":300}', '$' RETURNING CLOB) FROM DUAL;
    +----------------------------------------------------------+
    | JSON_QUERY('{"A":100,"B":200,"C":300}','$'RETURNINGCLOB) |
    +----------------------------------------------------------+
    | {"a": 100, "b": 200, "c": 300}                           |
    +----------------------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_QUERY('{"a":100, "b":200, "c":300}', '$' RETURNING VARCHAR2(200)) FROM DUAL;
    +-------------------------------------------------------------------+
    | JSON_QUERY('{"A":100,"B":200,"C":300}','$'RETURNINGVARCHAR2(200)) |
    +-------------------------------------------------------------------+
    | {"a": 100, "b": 200, "c": 300}                                    |
    +-------------------------------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_QUERY('{"a":100, "b":200, "c":300}', '$' RETURNING BLOB) FROM DUAL;
    +----------------------------------------------------------+
    | JSON_QUERY('{"A":100,"B":200,"C":300}','$'RETURNINGBLOB) |
    +----------------------------------------------------------+
    | {"a": 100, "b": 200, "c": 300}                           |
    +----------------------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_QUERY('{"a":100, "b":200, "c":300}', '$' RETURNING JSON) FROM DUAL;
    +----------------------------------------------------------+
    | JSON_QUERY('{"A":100,"B":200,"C":300}','$'RETURNINGJSON) |
    +----------------------------------------------------------+
    | {"a": 100, "b": 200, "c": 300}                           |
    +----------------------------------------------------------+
    1 row in set
    
    # Use the WRAPPER and ERROR clauses.
    obclient> SET @col_json = '[1,2]';
    obclient> SELECT JSON_QUERY(@col_json, '$[0 to 10]' RETURNING JSON WITH WRAPPER EMPTY ON ERROR) FROM DUAL;
    +----------------------------------------------------------------------+
    | JSON_QUERY(@COL_JSON,'$[0TO10]'RETURNINGJSONWITHWRAPPEREMPTYONERROR) |
    +----------------------------------------------------------------------+
    | [1, 2]                                                               |
    +----------------------------------------------------------------------+
    1 row in set
    
    # Use the ARRAY WRAPPER clause.
    obclient> SELECT JSON_QUERY(treat('{"a":100, "b":200, "c":300}' as json), '$' WITH ARRAY WRAPPER) AS value FROM DUAL;
    +----------------------------------+
    | VALUE                            |
    +----------------------------------+
    | [{"a": 100, "b": 200, "c": 300}] |
    +----------------------------------+
    1 row in set
    
    # Use the DISALLOW SCALAR clause.
    obclient> SELECT JSON_QUERY('"aaa"', '$' DISALLOW SCALARS ) FROM DUAL;
    +----------------------------------------+
    | JSON_QUERY('"AAA"','$'DISALLOWSCALARS) |
    +----------------------------------------+
    | NULL                                   |
    +----------------------------------------+
    1 row in set
    
    # Use the EMPTY OBJECT/EMPTY ARRAY ON EMPTY clause.
    obclient>SELECT JSON_QUERY('{}', '$.a' EMPTY OBJECT ON EMPTY) AS value FROM DUAL;
    +-------+
    | VALUE |
    +-------+
    | {}    |
    +-------+
    1 row in set
    
    obclient>SELECT JSON_QUERY('{}', '$.a' EMPTY ARRAY ON EMPTY) AS value FROM DUAL;
    +-------+
    | VALUE |
    +-------+
    | []    |
    +-------+
    1 row in set
    

    Previous topic

    JSON_VALUE
    Last

    Next topic

    JSON_EXISTS
    Next
    What is on this page
    Purpose
    Syntax
    Syntax
    Examples