我有以下示例查询,该查询从过程参数中获取值。该参数可以传递,也可以默认为null。
SELECT * FROM table
WHERE( table_term_code = '201931'
OR (table_term_code = '201931' and table_DETL_CODE ='CA02')
OR ( table_term_code = '201931' and table_ACTIVITY_DATE = sysdate)
OR ( table_term_code = '201931' and table_SEQNO = NULL));
即用户可以输入术语代码而不输入任何其他参数,或者可以输入术语代码和table_DETL_CODE而不输入任何其他输入参数。
其他两个或条件相同。
如果传递了术语代码并且table_DETL_CODE为null,则查询应返回该term_code的所有值,而此查询返回null。
是否有没有情况或在PL / SQL中达到条件的方法?
如果我对您的理解正确,那么这可能就是您要寻找的内容:
select *
from your_table
where (table_term_code = :par_term_code or :par_term_code is null)
and (table_detl_code = :par_detl_code or :par_detl_code is null)
and (table_activity_date = :par_activity_date or :par_activity_date is null)
and (table_seqno = :par_seqno or :par_seqno is null)