通配符与SQL LIKE运算符一起使用。SQL通配符用于在表中搜索数据。
SQL中的通配符为:%,_,[charlist],[^ charlist]
% -零个或多个字符的替代
Eg: //selects all customers with a City starting with "Lo" SELECT * FROM Customers WHERE City LIKE 'Lo%'; //selects all customers with a City containing the pattern "es" SELECT * FROM Customers WHERE City LIKE '%es%';
_-代替单个字符
Eg://selects all customers with a City starting with any character, followed by "erlin" SELECT * FROM Customers WHERE City LIKE '_erlin';
[charlist] -匹配的字符集和范围
Eg://selects all customers with a City starting with "a", "d", or "l" SELECT * FROM Customers WHERE City LIKE '[adl]%'; //selects all customers with a City starting with "a", "d", or "l" SELECT * FROM Customers WHERE City LIKE '[a-c]%';
[^ charlist] -仅匹配括号中未指定的字符
Eg://selects all customers with a City starting with a character that is not "a", "p", or "l" SELECT * FROM Customers WHERE City LIKE '[^apl]%'; or SELECT * FROM Customers WHERE City NOT LIKE '[apl]%' and city like '_%';