如何在 Oracle 中的 case 语句中用逗号分隔引号添加两个字符

How add two characters with quotes separated by comma in case statement in Oracle

我有一个场景,当案例验证成功时,案例语句中有 select 两个字符 'P'、'E',即 'ALL' = 'ALL' 以下是我要实现的目标:

select location,
grade,
City,
process_flag,
from table_v 
where process_flag in (
Case 
when :process_type = 'Processed' then 'P'
when :process_type = 'ERROR' then 'E'
when :process_type = 'ALL' then 'P','E'
ELSE process_flag
END;

Process_type 可以传递为 'Processed'、'ERROR'、'ALL'

如何实现?

您可以使用 ored 条件:

where 
       :process_type = 'Processed' and process_flag = 'P'
    or :process_type = 'ERROR'     and process_flag = 'E'
    or :process_type = 'ALL'       and process_flag in ('P', 'E')

您可以在 IN 子句中使用多个值:

WHERE ( :process_type, process_flag ) IN (
        ( 'Processed', 'P' ),
        ( 'ERROR',     'E' ),
        ( 'ALL',       'P' ),
        ( 'ALL',       'E' ),
      )

如果您想匹配 CASE 语句的 ELSE 子句,则:

WHERE ( :process_type, process_flag ) IN (
        ( 'Processed', 'P' ),
        ( 'ERROR',     'E' ),
        ( 'ALL',       'P' ),
        ( 'ALL',       'E' ),
      )
OR    :process_type NOT IN ( 'Processed', 'ERROR', 'ALL' )