SQLite like() Function
The SQLite like()
function checks if a given string matches a given pattern.
Syntax
Here is the syntax of the SQLite like()
function:
like(pattern, str[, escape])
Parameters
pattern
-
Required. The pattern that uses SQL wildcard syntax. It supports two wildcards:
%
and_
.%
can match any number of any characters,_
can match a single any character. str
-
Required. The string to check.
escape
-
Optional. The escape symbol, to escape wildcards in
pattern
.
Return value
The SQLite like()
function returns 1
or 0
. If like()
returned 1
, indicates the given string matches the given pattern; if like()
returned 0
, indicates the given string does not match the given pattern.
Examples
To check if hello
matches the pattern %el%
, use the following statement:
SELECT like('%el%', 'hello');
like('%el%', 'hello')
---------------------
1
Here, hello
whether matches the pattern %el%
.
To check if hello
matches the pattern %el__
, use the following statement:
SELECT like('%el__%', 'hello');
like('%el__%', 'hello')
-----------------------
1
Here, hello
matches the pattern %el__%
.
To check if hello
matches the pattern %el_
, use the following statement:
SELECT like('%el_', 'hello');
like('%el_', 'hello')
---------------------
0
Here, hello
does not match the pattern %el_
.