1、查詢包含某些字段的記錄(包含其中一個就符合):函數
對須要匹配的字符串建一個表 KEY_TABLEspa
ID | KEYWORD | TYPE |
1 | 字符串1 | 1 |
2 | 字符串2 | 1 |
3 | 字符串3 | 1 |
SELECT * FROM MAIN_TABLE mt ,KEY_TABLE s
WHERE mt.matching LIKE '%'||s.keyword||'%' (or)regexp
2、 查詢不包含這些字段的記錄:字符串
一、SELECT * FROM MAIN_TABLE mt
WHERE not regexp_like (mt.matching,'字符串1|字符串2|字符串3');table
(也能夠利用列轉行函數:class
SELECT * FROM MAIN_TABLE mt ,(SELECT t.type,listagg(t.keyword,'|') WITHIN GROUP(ORDER BY t.type) AS allkey
FROM KEY_TABLE t GROUP BY t.type) kt效率
WHERE not regexp_like (mt.matching,kt.keyword) and kt.type=1;查詢
)word
二、SELECT * FROM MAIN_TABLE mt
WHERE mt.matching not like '%字符串1%' and mt.matching not like '%字符串2%' and mt.matching not like '%字符串3%'; (效率比較高)tab