Oracle中的决策语句

问题描述 投票:0回答:1

我有一个条件,其中显示的记录取决于用户提供的值。

select calc_lvl1,   calc_lvl2,  calc_lvl3
from my_table
where comment=:user_value;

注释栏中的可能值为'NEW''ACCEPTED''REJECTED'。而且将来在此列中可能还会有新值,并且此查询将来也应该运行,而不管注释列中存在的不同值的数目如何。

我的要求是,如果用户不提供任何值,则应显示所有'NEW'记录,如果用户输入值'Y',则应显示除'NEW'以外的所有其他内容。

有什么方法可以实现?

oracle plsql oracle12c
1个回答
0
投票
select calc_lvl1, calc_lvl2, calc_lvl3
from my_table
where comment = user_value
  or (user_value is null and comment = 'NEW')
  or (user_value = 'Y' and comment <> 'NEW')
© www.soinside.com 2019 - 2024. All rights reserved.