方法:1、利用“select * from 表名 where order_no not like 字符”語句查詢;2、利用“select * from 表名 where not regexp_like(order_no,字符)”語句查詢。
本教程操作環境:Windows10系統、Oracle 11g版、Dell G3電腦。
oracle怎么查詢不包含指定字符
開發過程中遇到個需求,用戶要提取的數據列中不包含 YF、ZF、JD的字符串,
方法1:
select * from table where order_no not like '%YF%' and order_no not like '%ZF' and order_no not like '%JD%'
感 覺方法1有點笨,想到REGEXP_LIKE 可以實現包含多個,在前面加上 not 就可以實現不包含功能,方法如下:
方法2:
select * from table where not regexp_like(order_no,'YF|ZF|JD')
兩種方法都可以實現,但效率問題,經查詢兩個月11萬條數據做比效方法1用時18秒,方法2用時15秒,連續測試三次方法1總是比方法快2至3秒,如果數據量大的還是建議使用方法1!
推薦教程:《Oracle視頻教程》