當(dāng)我們將 INSTR() 函數(shù)與 MySQL WHERE 子句一起使用時,我們需要提供表的列名作為第一個參數(shù),提供子字符串作為第二個參數(shù)以及比較運算符。以下是使用“學(xué)生”表進行演示的示例 –
示例
假設(shè)“學(xué)生”表中有以下值 –
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)
登錄后復(fù)制
現(xiàn)在,以下查詢展示了如何將 INSTR() 函數(shù)與 WHERE caluse 一起使用 –
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)
登錄后復(fù)制
以上就是我們?nèi)绾螌?MySQL INSTR() 函數(shù)與 WHERE 子句一起使用?的詳細內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!






