ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
字符串对比函数 1、匹配字符 通配符%表示匹配0个或多个字符 通配符_表示匹配1个字符 ~~~ mysql> SELECT 'David!' LIKE 'David_'; -> 1 mysql> SELECT 'David!' LIKE '%D%v%'; -> 1 ~~~ 当匹配字符中有特殊字符时,可以用 \或者escape来指定特殊字符为字符 ~~~ mysql> SELECT 'David!' LIKE 'David\_'; -> 0 mysql> SELECT 'David_' LIKE 'David\_'; -> 1 mysql> SELECT 'David_' LIKE 'David|_' ESCAPE '|'; -> 1 ~~~ 2、expr NOT LIKE pat [ESCAPE 'escape_char'] 是上一个字符串对比函数的反义 3、STRCMP(expr1,expr2) 当expr1等于expr2时等于0,当expr1小于expr2时为-1,反之为1 ~~~ mysql> SELECT STRCMP('text', 'text2'); -> -1 mysql> SELECT STRCMP('text2', 'text'); -> 1 mysql> SELECT STRCMP('text', 'text'); -> 0 mysql> SET @s1 = _latin1 'x' COLLATE latin1_general_ci; mysql> SET @s2 = _latin1 'X' COLLATE latin1_general_ci; mysql> SET @s3 = _latin1 'x' COLLATE latin1_general_cs; mysql> SET @s4 = _latin1 'X' COLLATE latin1_general_cs; mysql> SELECT STRCMP(@s1, @s2), STRCMP(@s3, @s4); +------------------+------------------+ | STRCMP(@s1, @s2) | STRCMP(@s3, @s4) | +------------------+------------------+ | 0 | 1 | +------------------+------------------+ ~~~