Method 1: like
1.1 Traditional like lookup:
select 'this 是 china' like('%是%'); --true
select 'this 是 china' like '%是%'; --true
select 'this 是 china' like('%否%'); --false
select 'this 是 china' like '%否%'; --false
1.2 Regular expression-based search:
Refer to the usage of java regular expressions:
select 'this 是 china' rlike('是'); --true
select 'foobar' rlike('foo'); --true
select 'foobar' rlike('bar'); --true
select 'foobar' rlike('^f.*r$'); --true
Method 2: locate
usage:
return value | Function name | Function description |
---|---|---|
int | locate(string substr, string str[, int pos]) | [1. Parameter description: Parameter 1-substr: character substring to be searched; Parameter 2-str: original string; Parameter 3-pos: specified position, will search for the first occurrence of the specified string at this position and subsequent positions position.] …[English description: Returns the position of the first occurrence of substr in str after position pos.] |
Use Cases:
select locate('i','this is china'); --3
select locate('i','this is china',4); --6
select locate('i','this is china',7); --11
Method 3: regexp
usage:
operator | left and right operand types | Function description |
---|---|---|
A REGEXP B | strings | It belongs to relational operator, same as rlike function, judged according to java regular expression. [1. Parameter description: parameter 1-A: original string; parameter 2-B: substring to be compared] …[English description: NULL if A or B is NULL, TRUE if any (possibly empty) substring of A matches the Java regular expression B, otherwise FALSE. For example, 'foobar' RLIKE 'foo' evaluates to TRUE and so does 'foobar' RLIKE '^f. *r$'.] |
select 'this 是 china' regexp('是'); --true
--以下2种写法等价
select 'this 是 china' regexp('否'); --false
select 'this 是 china' regexp '否'; --false