OceanBase logo

OceanBase

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

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

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

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

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    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.3.1
    iconOceanBase Database
    SQL - V 4.3.1
    SQL
    KV
    • 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-15 08:25:15  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    share

    Purpose

    JSON_QUERY() finds one or more specified JSON values in JSON data and returns the values in a character string.

    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]);
    

    Parameters

    The parameters in the syntax are described as follows:

    • [RETURNING CLOB | BLOB | JSON | VARCHAR2 | VARCHAR2[size]: specifies the return value type. VARCHAR2[size] specifies the length of the return value. The default return value type depends on the input data type. If the input data type is JSON, the default return value type is JSON. If the input data type is VARCHAR, the default return value type is VARCHAR.

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

    • json_path_literal: specifies the query path.

    • PRETTY: specifies whether to use pretty-print for returning character data types.

    • ASCII: specifies to automatically escape any non-ASCII Unicode characters in the returned string by using standard ASCII Unicode escape sequences.

    • WITHOUT WRAPPER: specifies to ignore the ARRAY WRAPPER feature.

    • WITH WRAPPER: specifies to use the ARRAY WRAPPER feature.

    • WITH UNCONDITIONAL WRAPPER: This clause is equivalent to WITH WRAPPER.

    • WITH CONDITIONAL WRAPPER: specifies to use the ARRAY WRAPPER feature for returning multiple values and ignore the ARRAY WRAPPER feature for returning a single value.

    • ERROR:

      • NULL ON ERROR: specifies to return NULL when an error occurs. This is the default setting.
      • ERROR ON ERROR: specifies to return the corresponding Oracle error message when an error occurs.
      • EMPTY ON ERROR: This clause is equivalent to EMPTY ARRAY ON ERROR.
      • EMPTY ARRAY ON ERROR: specifies to return an empty JSON array when an error occurs.
      • EMPTY OBJECT ON ERROR: specifies to return an empty JSON object when an error occurs.
    • EMPTY:

      • NULL ON EMPTY: specifies to return NULL when no matching item is found. This is the default setting.
      • ERROR ON EMPTY: specifies to return the corresponding Oracle error message when no matching item is found.
      • EMPTY ON EMPTY: This clause is equivalent to EMPTY ARRAY ON EMPTY.
      • EMPTY ARRAY ON EMPTY: specifies to return an empty JSON array when no matching item is found.
      • EMPTY OBJECT ON EMPTY: specifies to return an empty JSON object when no matching item 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 EMTPY 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
    Parameters
    Examples