如何将 MySQL INSTR() 函数与 WHERE 子句结合使用?
mysqlmysqli database更新于 2025/5/18 13:00:17
当我们将 INSTR() 函数与 MySQL WHERE 子句结合使用时,我们需要提供表的列名作为第一个参数,子字符串作为第二个参数以及比较运算符。以下是使用 ‘Student’ 表来演示 − 的示例
示例
假设我们在 ‘Student’ 表中有以下值−
mysql> Select * from Student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 20 | Gaurav | Jaipur | Computers | | 21 | Yashraj | NULL | Math | +------+---------+---------+-----------+ 5 rows in set (0.02 sec)
现在,以下查询显示如何将 INSTR() 函数与 WHERE 子句一起使用 −
mysql> select name, INSTR(Name,'av')As Result from student where INSTR(Name,'av') > 0; +--------+--------+ | name | Result | +--------+--------+ | Gaurav | 5 | | Aarav | 4 | | Gaurav | 5 | +--------+--------+ 3 rows in set (0.00 sec) mysql> select name, INSTR(Name,'av')As Result from student where INSTR(Name,'av') = 0 ; +---------+--------+ | name | Result | +---------+--------+ | Harshit | 0 | | Yashraj | 0 | +---------+--------+ 2 rows in set (0.01 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/
打印
下一节:在将数据从文本文件导入 MySQL 表时,如果我们在文本文件中使用除反斜杠 () 之外的任何其他转义字符,MySQL 将如何评估? ❯❮ 上一节:哪些 MySQL 函数的工作方式与 LOCATE() 函数类似?

