条件 where 语句和比较运算符

Conditional where statement and comparison operator

我正在尝试减小 sql where 语句的大小以消除冗余子句“删除 union 语句。

我的说法是这样的:

SELECT
   col1, col2, col3...etc
FROM
   someTabe
WHERE
   col1 = :param
   and :sType = 1
UNION
SELECT
   col1, col2, col3...etc
FROM
   someTabe
WHERE
   col1 like '%'||:param||'%'
   and :sType = 2

这个语句的问题是对于每个 :sType 的可能性,我必须写一个 select 语句并合并所有的可能性,在我的例子中,我的 sql 语句即使没有工会也很长很复杂

所以我尝试将 where 语句重写为如下内容:

SELECT
   col1, col2, col3...etc
FROM
   someTabe
WHERE
   CASE WHEN :sType = 1 then col1= :param ELSE col1 like '%'||:param||'%' END

但这对 运行 来说是失败的,它需要在 case 语句之后的运算符,如 this question

那么,有没有语法可以实现上面语句中的思路呢?

一个简单的或者可能就足够了。

SELECT
   col1, col2, col3...etc
FROM
   someTabe
WHERE
   (:sType = 1 and col1 = :param )
or (:sType = 2 and col1 like '%'||:param||'%')

使用案例示例: Conditional WHERE clause with CASE statement in Oracle