正如已经评论过的,仅仅连接几个条件会更好更简单:
where departmentName like '%Medi%'
or departmentName like '%Ciga%'
or departmentName like '%Tabacc%';
另一种方法是将这些值 '%Medi%'、'%Ciga%' 和 '%Tabacc%' 插入到条件表中,然后运行以下查询:
select department.*
from department
cross join conditionTable
where department.departmentName like conditionTable.value;
我在这里假设您的 table 是department
并且 conditionTable 有一个 column value
。如果您实施此解决方案,您应该关心并发性,并通过类似的方式过滤条件表
select department.*
from department
inner join conditionTable on conditionTable.session = yourSessionId
where department.departmentName like conditionTable.value;
最后,如果您不想使用条件表,第三种可能很方便的解决方案是生成一个字符串select <cond1> as value from dual union select <cond2> from dual...
并将其放入动态查询中
select department.*
from department
cross join
(select '%Medi%' as value from dual
union
select '%Ciga%' from dual
union
select '%Tabacc%' from dual) conditionTable
where department.departmentName like conditionTable.value;