我被困在 Oracle Apex(22.1.0-17)中的一個微不足道的場景中。
我有一個帶有一些“通知”的經典報告(如下所示)和一個標志 - 如果表中的某些特定記錄被讀取(理論上) - IS_READ 列中的 Y/N 值。

然后在相應的查詢中,我會有一個這樣的 where 子句:
select ...
from ...
where ...
and (:P2_IS_READ is null -- will show everything when you select the "All"
or :P2_IS_READ = IS_READ -- only show what matches
)
uj5u.com熱心網友回復:
這是一個選項:
選擇串列 LoV 查詢:
SQL> select 'Yes' d, 'Y' r from dual union all
2 select 'No' d, 'N' r from dual union all
3 select 'All' d, 'A' r from dual;
D R
--- -
Yes Y
No N
All A
SQL>
經典報表查詢:
select *
from notification
where is_read = case when :P1_IS_READ = 'Y' then 'Y'
when :P1_IS_READ = 'N' then 'N'
when :P1_IS_READ = 'A' then is_read
end
order by id;
為了說明它(使用 SQL*Plus;切換到替換變數),使用示例表:
SQL> select * from notification;
ID NAME IS_READ
---------- ------ -------
1 Little Y
2 Foot N
3 Crisp N
閱讀通知:
SQL> select *
2 from notification
3 where is_read = case when '&&P1_IS_READ' = 'Y' then 'Y'
4 when '&&P1_IS_READ' = 'N' then 'N'
5 when '&&P1_IS_READ' = 'A' then is_read
6 end
7 order by id;
Enter value for p1_is_read: Y
ID NAME IS_READ
---------- ------ -------
1 Little Y
未讀通知:
SQL> undefine p1_is_read
SQL> /
Enter value for p1_is_read: N
ID NAME IS_READ
---------- ------ -------
2 Foot N
3 Crisp N
所有通知:
SQL> undefine p1_is_read
SQL> /
Enter value for p1_is_read: A
ID NAME IS_READ
---------- ------ -------
1 Little Y
2 Foot N
3 Crisp N
SQL>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/466332.html
