mysql中的instr 函式的用法

2021-09-30 17:18:02 字數 557 閱讀 5765

有時,想要在字串中查詢某字串可以使用instr()函式

instr()返回子字串在字串中首次出現的位置;如果沒有找到,則返回0

用法:instr(str,substr)

str:從哪個字串中搜尋

substr:要搜尋的子字串

instr()函式不區分大小寫

mysql instr()函式示例:

如圖,在abcd字串中查詢是否含有字串b,返回的字串位置是2. 說明instr()函式返回的位置是從1開始的,如果找不到則返回0

查詢字串中包含「民」的記錄

instr()函式與like運算子

在沒有索引的情況下,instr()函式與like運算子的速度是一樣的;在具有字首搜尋的like運算子下,使用like運算子速度會更快一些

mysql中INSTR函式的用法

mysql中instr函式的用法 instr 欄位名,字串 這個函式返回字串在某乙個欄位的內容中的位置,沒有找到字串返回0,否則返回位置 從1開始 select from tbltopic order by instr topictitle,ha 0 desc select instr topict...

Mysql的instr 函式用法

mysql的內建函式instr filed,str 作用是返回str子字串在filed字串的第一次出現的位置。當instr filed,str 0時,表示子符串str不存在於字串filed中,因此可以用來實現mysql中的模糊查詢,與like用法類似。如下 1 instr 函式,為引數 select...

Oracle中的instr函式

在oracle pl sql中,instr函式返回string2在string1中出現的位置,語法如下 例項1.從起始位置開始搜尋,第一次出現子串的位置 sql select instr chen linbo bobo12082119 bo 1,1 from dual instr chen linb...