Oracle 某一列或者几列 检查在某个字符集合中

    xiaoxiao2021-04-16  33

    如题 ,此类问题 需要考虑查询效率和oracle 语句 in 的条数限制。常用的方法是 如下:

    1、假设数据库表为A 字段为 field ,那么常见语句为 a.field in ('1','2','3'....);  类似这种语句 但是这个in 子句有条数限制,这样你需要改良为(a.field in ('1','2','3',...,'999')  or a.field in ('1001','1002','1003',...,'1999') or..)类似这种

    但是这种效率确实不太高

    2、我尝试使用一下方法 exists (select * from ( select regexp_substr('1,2,3...' ,'[^,]+', 1, rownum) n from dual connect by rownum <= 50)where A.field  = n and n is not null)) 这样会变成都n 的列的查询 感觉效率会高一些

       但是遗憾的是 regexp_substr()这个函数接受的字符串长度也有限制 所以只能改良为

    exists (select * from ( 

    select regexp_substr('1,2,3...' ,'[^,]+', 1, rownum) n from dual connect by rownum <= 50)

    union

    select regexp_substr('51,52,53...' ,'[^,]+', 1, rownum) n from dual connect by rownum <= 50)

    union

    ...

    where A.field  = n and n is not null)

    不知道这个效率如何 待验证  

        

    转载请注明原文地址: https://ju.6miu.com/read-673111.html

    最新回复(0)