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

    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.1.0
    iconOceanBase Database
    SQL - V 4.1.0
    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_VALUE

    Last Updated:2023-07-28 02:55:42  Updated
    share
    What is on this page
    Purpose
    Syntax
    Note
    Parameters
    Error handling
    Examples

    folded

    share

    Purpose

    JSON_VALUE() extracts a value in a JSON document from the specified path and returns the extracted value. You can also set the function to convert the extracted value to the desired data type.

    Syntax

    JSON_VALUE(json_doc, path [RETURNING type] [on_empty] [on_error])
    
    on_empty:
        {NULL | ERROR | DEFAULT value} ON EMPTY
    
    on_error:
        {NULL | ERROR | DEFAULT value} ON ERROR
    

    Note

    Parameters

    This section describes the related parameters:

    • json_doc specifies the JSON document.

    • path is a JSON path that points to a location in the document, and must be a string.

    • type supports the following data types:

      • FLOAT

      • DOUBLE

      • DECIMAL

      • SIGNED

      • UNSIGNED

      • DATE

      • TIME

      • DATETIME

      • YEAR. Note that YEAR(1) and YEAR(2) are not supported.

      • CHAR

      • JSON

    • If you do not use a RETURNING clause, the data type of the return value of the function is VARCHAR(512). If you do not specify the character set for the return type, JSON_VALUE() uses the UTF8MB4 character set and a binary collation, and the return value is case-sensitive. If you specify the UTF8MB4 character set for the result, the server uses the default collation for the character set, and the return value is case-insensitive.

    • You can specify the on_empty clause to determine the behavior of JSON_VALUE() when no data is found at the specified path. Supported values of this clause:

      • NULL ON EMPTY: specifies that JSON_VALUE() returns NULL. This is the default value of on_empty.

      • DEFAULT value ON EMPTY': returns the specified value whose type must match the value of the return type.

      • ERROR ON EMPTY: returns an error.

    • When an error occurs, on_error takes one of the following values:

      • NULL ON ERROR: JSON_VALUE() returns NULL. If you do not specify the ON ERROR clause, this is the default behavior.

      • DEFAULT value ON ERROR: returns the specified value whose type must match the value of the return type.

      • ERROR ON ERROR: returns an error.

      Notice

      When you specify the on_empty clause, you must put it before all ON ERROR clauses.

    Error handling

    JSON_VALUE() checks the validity of all JSON inputs of documents and paths. If an input is invalid, an SQL error is returned without triggering the ON ERROR clause.

    The ON ERROR clause is triggered if one of the following events occurs:

    • When you try to extract an object or array, the specified path is parsed into multiple paths in the JSON document.

    • A conversion error occurs when you, for example, try to convert 'asdf' to an UNSIGNED value.

    • Data is truncated.

    Even if you specify NULL ON ERROR or DEFAULT ... ON ERROR, a conversion error always triggers an alert.

    When the source JSON document specified for json_doc contains no data at the specified path, the ON EMPTY clause is triggered.

    Examples

    obclient> SELECT JSON_VALUE('{"fname": "Smith", "lname": "Will"}', '$.fname');
    +--------------------------------------------------------------+
    | JSON_VALUE('{"fname": "Smith", "lname": "Will"}', '$.fname') |
    +--------------------------------------------------------------+
    | Smith                                                        |
    +--------------------------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_VALUE('{"item": "shoes", "price": "69.73"}', '$.price'
         RETURNING DECIMAL(4,2)) AS price;
    +-------+
    | price |
    +-------+
    | 69.73 |
    +-------+
    1 row in set
    

    Previous topic

    JSON_SEARCH
    Last

    Next topic

    MEMBER OF
    Next
    What is on this page
    Purpose
    Syntax
    Note
    Parameters
    Error handling
    Examples