天天看點

oracle instr妙用與坑

用法

instr(‘originStr’ , ‘targetStr’ , index , count);

簡單說明

originStr:要比對的源字元

targetStr:要比對的目标字元

index:從第幾個開始比對

count:比對第幾次

傳回:如果比對到傳回目标字元在源字元的下标位置,不比對傳回-1

我一般用它判斷字元串A中是否存在字元串B

後來意外發現可以用來過濾勾選的情況

oracle instr妙用與坑

一般勾選後拼接為IDS:19285,19286

但這得到的是字元串類型的,不能直接用 id in(IDS)

是以可以這樣妙用

select t.* from 明細表 t

where instr(’,’|| IDS ||’,’ , ‘,’|| t.id ||’,’)>0

就是把id串左右引起來判斷是否>0(存在)

起初以為這個用法很好。

但是在資料多的情況下是很慢的

分析如下

oracle instr妙用與坑
oracle instr妙用與坑

可以發現instr 沒有索引,全表查詢啥的。。。不太懂,是以說是很慢的

引出文章

regexp_substr

connect by level