mysql中instr=0为什么会返回所有的结果

mysql中instr=0为什么会返回所有的结果,第1张

instr() > 0 返回的是模糊查询匹配到的数据  类似于like

instr() = 0  返回的是没有模糊匹配到的数据  可以理解为>0的补集

instr() < 0  直接返回null  空数据

一般情况下,进行模糊查询  我们用第一种写法:

SELECT * FROM table_name WHERE INSTR(column_name,'模糊匹配的字符串')>0

SUBSTRING(str FROMpos)

 返回字符串str的位置pos起的一个子串

mysql>selectSUBSTRING('Quadratically',5)

->'ratically'

mysql>select SUBSTRING('foobarbar' FROM4)

->'barbar'

INSTR(str,substr)

返回子串substr在字符串str中的第一个出现的位置。这与有2个参数形式的LOCATE()相同,除了参数被颠倒。

mysql>select INSTR('foobarbar', 'bar')

->4

mysql>select INSTR('xbar', 'foobar')

->0

可以使用 not like

LIKE *** 作符用于在 WHERE 子句中搜索列中的指定模式

not like 即表示不包含某条件

例子:

Persons 表:

Id LastName FirstName Address City

1AdamsJohnOxford StreetLondon

2BushGeorgeFifth AvenueNew York

3CarterThomasChangan StreetBeijing

选取居住在不包含 "lon" 的城市里的人

SELECT * FROM Persons WHERE City NOT LIKE '%lon%'

结果集:

Id LastName FirstName Address City

2BushGeorgeFifth AvenueNew York

3CarterThomasChangan StreetBeijing


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7446521.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存