In real-world project development, fuzzy matches are often needed, such as matching a part of a column value. SQL provides four methods of matching:
1,% matching
There are several different uses for% matching. %atm%, before and after all can be used to match, the result can be "atmmm", "Ggatm", "Bbatmaa";
select * from tableinfo where name like "%atm%";
If you need to match two characters or a string, you can connect with and.
select * from tableinfo where name like "%atm%" and name like "%bank%";
If you need to skip a string search.
select * from tableinfo where name like "%atm%bank%";
2. [] Match
Represents one of the characters listed in parentheses. Specifies a character or string, or range of numbers, and so on, requiring that the matched object be any of them.
select * from tableinfo where name like "atm[1、2、3]";
That is, you can only get a result set of ATM1,ATM2.ATM3 values.
3, ^] Match
Represents any one of the characters listed in parentheses. Specifying a character or string, or a range of numbers, and so on, requires that the matched object be any of the following except them.
select * from tableinfo where name like "atm[^1、2、3]";
That is, you can only get a result set other than the ATM1,ATM2.ATM3 value.
4, _ Match
Represents any single character.
select * from tableinfo where name like "_atm";select * from tableinfo where name like "atm_";
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SQL like fuzzy query