您好,欢迎访问一九零五行业门户网

可与 NOT LIKE 运算符一起使用的不同通配符有哪些?

众所周知,not like 运算符与 wildcard 字符一起使用,用于不获取具有指定字符串的字符串。基本上,通配符是帮助搜索匹配复杂条件的数据的字符。以下是可与 not like 运算符结合使用的通配符类型:
% - 百分比“%”通配符用于指定 0、1 模式或更多字符。将 % 通配符与 not like 运算符一起使用的基本语法如下:
select statement…where column_name not like ‘x%’
这里 x是任何指定的起始模式,例如more和%的单个字符匹配从0开始的任意数量的字符。
百分比'%'通配符可以以多种方式与指定模式配合。以下是一些示例,显示了带有 % 的不同 not like 运算符。在这些示例中,x 代表指定的模式:
1。不像“x%”:它将查找除以“x”开头的任何值。
示例
mysql> select * from student where name not like 'a%';+------+---------+---------+-----------+--------------------+| id | name | address | subject | year_of_admission |+------+---------+---------+-----------+--------------------+| 1 | gaurav | delhi | computers | 2001 || 15 | harshit | delhi | commerce | 2009 || 20 | gaurav | jaipur | computers | 2017 || 21 | yashraj | null | math | 2000 |+------+---------+---------+-----------+--------------------+4 rows in set (0.00 sec)
2。与‘%x’不同:它将查找除以“x”结尾的任何值。
示例
mysql> select * from student where name not like '%v';+------+---------+---------+----------+--------------------+| id | name | address | subject | year_of_admission |+------+---------+---------+----------+--------------------+| 15 | harshit | delhi | commerce | 2009 || 21 | yashraj | null | math | 2000 |+------+---------+---------+----------+--------------------+2 rows in set (0.00 sec)
3。与“%x%”不同:它将查找除任何位置上有“x”的值之外的任何值。
示例
mysql> select * from student where name not like '%h%';+------+--------+---------+-----------+--------------------+| id | name | address | subject | year_of_admission |+------+--------+---------+-----------+--------------------+| 1 | gaurav | delhi | computers | 2001 || 2 | aarav | mumbai | history | 2010 || 20 | gaurav | jaipur | computers | 2017 |+------+--------+---------+-----------+--------------------+3 rows in set (0.00 sec)
4。 not like 'x%x':它将查找除以“x”开头并以“x”结尾的值以外的任何值。
示例
mysql> select * from student where name not like 'a%v';+------+---------+---------+-----------+--------------------+| id | name | address | subject | year_of_admission |+------+---------+---------+-----------+--------------------+| 1 | gaurav | delhi | computers | 2001 || 15 | harshit | delhi | commerce | 2009 || 20 | gaurav | jaipur | computers | 2017 || 21 | yashraj | null | math | 2000 |+------+---------+---------+-----------+--------------------+4 rows in set (0.00 sec)
_ 下划线下划线通配符用于精确匹配一个字符。将 _ 通配符与 not like 运算符一起使用的基本语法如下:
select 语句...where column_name not like 'x_'
此处 x 是任何指定的起始模式,例如 more 的单个字符,_ 恰好匹配一个字符。
可以单独使用下划线“_”通配符或与 % 结合,以多种方式与指定模式结合。以下是一些示例,显示了带有 % 的不同 not like 运算符。在这些示例中,x 代表指定的模式:
1。与“x_”不同:它将查找除以“x”开头且 x 后只有一个字符以外的任何值。
示例
mysql> select * from student where year_of_admission not like '200_';+------+--------+---------+-----------+--------------------+| id | name | address | subject | year_of_admission |+------+--------+---------+-----------+--------------------+| 2 | aarav | mumbai | history | 2010 || 20 | gaurav | jaipur | computers | 2017 |+------+--------+---------+-----------+--------------------+2 rows in set (0.00 sec)
2。与“_x”不同:它将查找除以“x”结尾且 x 之前只有一个字符以外的任何值。
示例
mysql> select * from student where year_of_admission not like '_017';+------+---------+---------+-----------+--------------------+| id | name | address | subject | year_of_admission |+------+---------+---------+-----------+--------------------+| 1 | gaurav | delhi | computers | 2001 || 2 | aarav | mumbai | history | 2010 || 15 | harshit | delhi | commerce | 2009 || 21 | yashraj | null | math | 2000 |+------+---------+---------+-----------+--------------------+4 rows in set (0.00 sec)
3。 not like _x%:它与 % 通配符结合使用。它将找到除第二个位置有 x 之外的任何值。
示例
mysql> select * from student where name not like '_a%';empty set (0.00 sec)
4。与 x_%_% 不同: 它与 % 通配符结合使用。它将查找除以 x 开头且长度至少为三个字符以外的任何值。
示例
mysql> select * from student where name not like 'g_%_%';+------+---------+---------+----------+--------------------+| id | name | address | subject | year_of_admission |+------+---------+---------+----------+--------------------+| 2 | aarav | mumbai | history | 2010 || 15 | harshit | delhi | commerce | 2009 || 21 | yashraj | null | math | 2000 |+------+---------+---------+----------+--------------------+3 rows in set (0.00 sec)
以上就是可与 not like 运算符一起使用的不同通配符有哪些?的详细内容。
其它类似信息

推荐信息