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