首页 > 解决方案 > SQL Select 列出多个带大小写的值,然后

问题描述

我有一个变量,并且基于我想从选择命令中排除该值的变量。如果我想排除 1 个字符串,它可以正常工作,但如果我在相同条件下排除多个字符串,则它不起作用。这是代码。当变量是 abc 和 EFG 时它工作正常,但对于 XYZ 我想排除“abc”和“efg”

select table.column1
from table
where column1 not like
        case 
            when variable = 'abc' THEN '%abc%'
            when variable  = 'EFG' THEN '%efg%'
            when variable  = 'XYZ' THEN '%abc%' and '%efg%'
        else 
              '_'
        END

我尝试使用 '%abc%' 和 '%efg%' 和 '%(abc|efg)%' 和 '%abc%' || 和 || '%efg%',但它们似乎都没有工作。

标签: sqloracleoracle-apex

解决方案


我想你想要:

where (variable = 'abc' and column1 not like '%abc%') or
      (variable = 'EFG' and column1 not like '%EFG%') or
      (variable = 'XYZ' and column1 not like '%abc%' and column1 not like '%XYZ%') or
      (variable not in ('abc', 'EFG', 'XYZ'))

推荐阅读