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.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 & 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.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    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

    Pattern-matching conditions

    Last Updated:2026-04-02 06:23:58  Updated
    share
    What is on this page
    LIKE condition
    Syntax
    Parameters
    Considerations
    Examples
    REGEXP_LIKE condition
    Syntax
    Parameters
    Considerations
    Examples

    folded

    share

    Pattern-matching conditions compare character data.

    Pattern-matching conditions are LIKE and REGEXP_LIKE.

    LIKE condition

    The LIKE condition is used for pattern matching. The equality operator (=) indicates that one character value exactly matches another character value. The LIKE condition matches a part of a character value with another character value by searching the first value for the pattern specified by the second character value.

    The LIKE condition uses characters defined in the input character set to calculate strings.

    Syntax

    char1 [NOT] LIKE char2 [ ESCAPE esc_char ]
    

    Note

    When the LIKE condition contains a double vertical bar (||), it can be used as a logical OR operator depending on the value of sql_mode.

    • When sql_mode does not contain PIPES_AS_CONCAT, || is identified as a logical OR operator.
    • When sql_mode contains PIPES_AS_CONCAT, || is identified as a character concatenation operator.

    Parameters

    Parameter Description
    char1 A character expression, such as a character column, which is called the search value.
    char2 A character expression, which is usually a literal and called pattern.
    esc_char A character expression, which is usually a literal. ESCAPE identifies esc_char as an escape character. When an escape character is placed prior to a pattern-matching character, this pattern-matching character is interpreted as a common character.

    Considerations

    If esc_char is not specified, no default escape character is available. If the value of char1, char2, or esc_char is NULL, the result is unknown. Otherwise, the escape character (if any) must be a character string of length 1.

    All character expressions (char1, char2, and esc_char) can be of any data type, such as CHAR, VARCHAR2, NCHAR, and NVARCHAR2. If the character expressions are of different data types, OceanBase Database will convert all of them into the data type of char1.

    Special pattern-matching characters that the pattern can contain are as follows:

    • The underscore (_) exactly matches one character in the value rather than one byte of a multi-byte character set.

    • The percent sign (%) matches zero or multiple characters in the value rather than bytes in a multi-byte character set. The pattern "%" cannot match NULL.

    • If no wildcard character is detected, LIKE can be converted into the equal sign (=). For example, SELECT * FROM t1 WHERE c1 LIKE 'ABC'; is equivalent to "filter("c1"='abc')".

    You can use the ESCAPE clause to contain actual characters % or _ in a pattern. If an escape character is placed prior to the % or _ character in a pattern, OceanBase Database interprets this character literally, rather than identifying it as a special patter-matching character. You can also search for the escape character itself. For example, if @ is the escape character, you can search for @ by using @@.

    Note

    Only ASCII-equivalent underscore (_) and percent sign (%) characters are identified as patter-matching characters. The full-width variants of underscore (_) and percent sign (%) characters in East Asian and Unicode character sets are identified as common characters.

    In the following example, if x [does not] match pattern y, TRUE is returned. In y, the % character matches any string with zero or multiple characters, except NULL, and the _ character matches any single character. Any character, except the percent sign (%) and underscore (_), can follow the ESCAPE clause. If a wildcard character is preceded with an escape character, the wildcard character is identified as a literal.

    x [NOT] LIKE y [ESCAPE 'z']
    

    Examples

    In the following statement with the LIKE condition, the ESCAPE '\' clause will interpret the pattern-matching character _ behind \ in %A\_B% as a common character.

    SELECT last_name FROM emp WHERE last_name LIKE '%A\_B%' ESCAPE '\' ORDER BY last_name;
    

    REGEXP_LIKE condition

    The REGEXP_LIKE condition is used for regular expression matching. It evaluates strings by using the characters defined in the input character set.

    Syntax

    REGEXP_LIKE(source_char, pattern [, match_param ])
    

    Parameters

    Parameter Description
    source_char A character expression used as the search value. The data type can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB.
    pattern A regular expression, which is usually a text literal. The data type can be CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
    match_param A character expression of the VARCHAR2 or CHAR data type that is used to change the default matching behavior of the condition.

    Considerations

    pattern contains a maximum of 512 bytes. If the data type of pattern is different from that of source_char, OceanBase Database converts the data type of pattern into that of source_char.

    You can specify one or more of the following values for match_parameter:

    • 'i': indicates case-insensitive matching.

    • 'c': indicates case-sensitive matching.

    • 'n': indicates allowing the period (.) to match the line feed character. If this option is omitted, the period does not match the line feed character.

    • 'm': indicates interpreting the source string as multiple lines. OceanBase Database interprets ^ and $ as the beginning and end of any line in the source string, instead of the beginning and end of the entire source string. If this option is omitted, OceanBase Database identifies the source string as a single line.

    • 'x': indicates ignoring whitespace characters. By default, a whitespace character matches itself.

    If you specify multiple conflicting values for match_parameter, OceanBase Database will use the last value. For example, if you specify 'ic' for match_parameter, OceanBase Database uses case-sensitive matching. If you specify other values, an error is returned.

    If match_parameter is omitted, the following matching rules apply:

    • By default, the value of the NLS_SORT system variable determines whether case-sensitive matching is adopted.

    • The period (.) does not match the line feed character.

    • The source string is identified as a single line.

    Examples

    Create a table named emp and insert data into it.

    CREATE TABLE emp(manager_id INT, first_name VARCHAR(50), last_name VARCHAR(50), hiredate VARCHAR(50),salary INT);
    INSERT INTO emp VALUES(300, 'Steven', 'King',  '2019-09-11',23600);     
    INSERT INTO emp VALUES(200, 'Steven', 'Markle', '2019-11-05', 23800);
    INSERT INTO emp VALUES(100, 'Deven',  'Part',  '2018-10-01',24000);     
    INSERT INTO emp VALUES(200, 'Carlos', 'Ross',  '2019-06-11',23500);     
    INSERT INTO emp VALUES(200, 'Teven',  'Bell', '2019-05-25', 23000);
    INSERT INTO emp VALUES(200, 'Stephen', 'Stiles',  '2018-06-11',24500);    
    INSERT INTO emp VALUES(100, 'Ame', 'De Haan', '2018-05-01',11000);      
    INSERT INTO emp VALUES(100, 'Jon', 'Errazuriz', '2017-07-21', 1400);   
    COMMIT;
    

    Query the first name and last name for employees whose first name is Steven or Stephen. (first_name begins with Ste and ends with en, and v or ph lies between.)

    obclient> SELECT first_name, last_name FROM emp WHERE REGEXP_LIKE (first_name, '^Ste(v|ph)en$')
    ORDER BY first_name, last_name;
    +------------+-----------+
    | FIRST_NAME | LAST_NAME |
    +------------+-----------+
    | Stephen    | Stiles    |
    | Steven     | King      |
    | Steven     | Markle    |
    +------------+-----------+
    3 rows in set
    

    Query the last name for employees whose last name contains a double vowel. (last_name contains two adjacent case-insensitive vowels a, e, i, o, or u.)

    obclient> SELECT last_name
         FROM emp
         WHERE REGEXP_LIKE (last_name, '([aeiou])\1', 'i')
         ORDER BY last_name;
    +-----------+
    | LAST_NAME |
    +-----------+
    | De Haan   |
    +-----------+
    1 row in set
    

    Previous topic

    Logical conditions
    Last

    Next topic

    NULL conditions
    Next
    What is on this page
    LIKE condition
    Syntax
    Parameters
    Considerations
    Examples
    REGEXP_LIKE condition
    Syntax
    Parameters
    Considerations
    Examples