Is there a combination of “LIKE” and “IN” in SQL?

后端 未结 25 1647
灰色年华
灰色年华 2020-11-22 03:08

In SQL I (sadly) often have to use \"LIKE\" conditions due to databases that violate nearly every rule of normalization. I can\'t change that right now. But tha

相关标签:
25条回答
  • 2020-11-22 04:01

    In Oracle RBDMS you can achieve this behavior using REGEXP_LIKE function.

    The following code will test if the string three is present in the list expression one|two|three|four|five (in which the pipe "|" symbol means OR logic operation).

    SELECT 'Success !!!' result
    FROM dual
    WHERE REGEXP_LIKE('three', 'one|two|three|four|five');
    
    RESULT
    ---------------------------------
    Success !!!
    
    1 row selected.
    

    Preceding expression is equivalent to:

    three=one OR three=two OR three=three OR three=four OR three=five
    

    So it will succeed.

    On the other hand, the following test will fail.

    SELECT 'Success !!!' result
    FROM dual
    WHERE REGEXP_LIKE('ten', 'one|two|three|four|five');
    
    no rows selected
    

    There are several functions related to regular expressions (REGEXP_*) available in Oracle since 10g version. If you are an Oracle developer and interested this topic this should be a good beginning Using Regular Expressions with Oracle Database.

    0 讨论(0)
提交回复
热议问题