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

    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.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    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_SEARCH

    Last Updated:2024-12-02 03:48:26  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Description
    Examples

    folded

    Share

    Purpose

    JSON_SEARCH() returns the path to the specified string in a JSON document.

    Syntax

    JSON_SEARCH(json_doc, one_or_all, search_str[, escape_char[, path] ...])
    

    Description

    json_doc specifies the JSON document. search_str specifies the search string. escape_char specifies the constant expression. path specifies the path.

    If any argument is NULL, the return value is NULL. If no path exists in the document or the specified string is not found, the return value is NULL.

    You can set one_or_all to one of the following values:

    • 'one': The search stops after the first match, and a path string is returned.

    • 'all': The search returns all matching path strings, and no duplicate paths are included. Multiple strings are automatically wrapped into an array. However, the array elements are not in a defined order.

    The percent sign (%) and underscore (_) in search_str have the same effect as the LIKE operator:

    • % matches any number of characters, including zero characters.

    • _ matches one character.

    To specify a % or _ in the search string, add an escape character before it. If the escape_char is missing or NULL, the default escape character is a backslash (\). Otherwise, escape_char must be a constant that is empty or one character.

    search_str and path are always used as utf8mb4 strings, regardless of their actual encoding value.

    An error occurs in the following cases:

    • The JSON document specified for json_doc is invalid.

    • The path expression specified for path is invalid.

    • one_or_all is set to a value other than 'one' or 'all'.

    • escape_char is not a constant expression.

    Examples

    obclient> SET @jn = '["abcd", [{"k": "10"}, "efg"], {"x":"abcd"}, {"y":"cdef"}]';
    Query OK, 0 rows affected
    
    obclient> SELECT JSON_SEARCH(@jn, 'one', 'abcd');
    +---------------------------------+
    | JSON_SEARCH(@jn, 'one', 'abcd') |
    +---------------------------------+
    | "$[0]"                          |
    +---------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', 'abcd');
    +---------------------------------+
    | JSON_SEARCH(@jn, 'all', 'abcd') |
    +---------------------------------+
    | ["$[0]", "$[2].x"]              |
    +---------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', 'ghk');
    +--------------------------------+
    | JSON_SEARCH(@jn, 'all', 'ghk') |
    +--------------------------------+
    | NULL                           |
    +--------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '10');
    +-------------------------------+
    | JSON_SEARCH(@jn, 'all', '10') |
    +-------------------------------+
    | "$[1][0].k"                   |
    +-------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '10', NULL, '$');
    +------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '10', NULL, '$') |
    +------------------------------------------+
    | "$[1][0].k"                              |
    +------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '10', NULL, '$[*]');
    +---------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '10', NULL, '$[*]') |
    +---------------------------------------------+
    | "$[1][0].k"                                 |
    +---------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '10', NULL, '$[*][0].k');
    +--------------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '10', NULL, '$[*][0].k') |
    +--------------------------------------------------+
    | "$[1][0].k"                                      |
    +--------------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '10', NULL, '$[1]');
    +---------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '10', NULL, '$[1]') |
    +---------------------------------------------+
    | "$[1][0].k"                                 |
    +---------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '10', NULL, '$[1][0]');
    +------------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '10', NULL, '$[1][0]') |
    +------------------------------------------------+
    | "$[1][0].k"                                    |
    +------------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', 'abc', NULL, '$[2]');
    +----------------------------------------------+
    | JSON_SEARCH(@jn, 'all', 'abc', NULL, '$[2]') |
    +----------------------------------------------+
    | NULL                                         |
    +----------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '%a%');
    +--------------------------------+
    | JSON_SEARCH(@jn, 'all', '%a%') |
    +--------------------------------+
    | ["$[0]", "$[2].x"]             |
    +--------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '%b%');
    +-------------------------------+
    | JSON_SEARCH(@jn, 'all', '%b%') |
    +-------------------------------+
    | ["$[0]", "$[2].x", "$[3].y"]  |
    +-------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '%b%', NULL, '$[0]');
    +---------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '%b%', NULL, '$[0]') |
    +---------------------------------------------+
    | "$[0]"                                      |
    +---------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '%b%', NULL, '$[2]');
    +---------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '%b%', NULL, '$[2]') |
    +---------------------------------------------+
    | "$[2].x"                                    |
    +---------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '%b%', NULL, '$[1]');
    +---------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '%b%', NULL, '$[1]') |
    +---------------------------------------------+
    | NULL                                        |
    +---------------------------------------------+
    1 row in set
    
    obclient> SELECT JSON_SEARCH(@jn, 'all', '%b%', '', '$[1]');
    +-------------------------------------------+
    | JSON_SEARCH(@jn, 'all', '%b%', '', '$[1]') |
    +-------------------------------------------+
    | NULL                                      |
    +-------------------------------------------+
    1 row in set
    

    Previous topic

    JSON_OVERLAPS
    Last

    Next topic

    JSON_VALUE
    Next
    What is on this page
    Purpose
    Syntax
    Description
    Examples