一、查询包含某些字段的记录(包含其中一个就符合):
对需要匹配的字符串建一个表 KEY_TABLE
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)二、 查询不包含这些字段的记录:
1、SELECT * FROM MAIN_TABLE mt
WHERE not regexp_like (mt.matching,'字符串1|字符串2|字符串3');(也可以利用列转行函数:
SELECT * FROM MAIN_TABLE mt ,(SELECT t.type,listagg(t.keyword,'|') WITHIN GROUP(ORDER BY t.type) AS allkeyFROM KEY_TABLE t GROUP BY t.type) kt
WHERE not regexp_like (mt.matching,kt.keyword) and kt.type=1;
)
2、SELECT * FROM MAIN_TABLE mt WHERE mt.matching not like '%字符串1%' and mt.matching not like '%字符串2%' and mt.matching not like '%字符串3%'; (效率比较高)