【发布时间】:2014-02-28 00:26:07
【问题描述】:
我有一个带有可选参数的函数/过程。如果提供,我需要将参数用作游标的条件。如果没有提供,那么我不想要那个条件。
这是我想出的一个非常简化的版本:
create or replace procedure check_data
(p_parm1 in varchar2 default null,
p_parm2 in number default null)
is
begin
if (p_parm1 is null && p_parm2 is null) then
for rec in (select col_1, col_2
from table_a)
loop
/*Statements, use rec.col_1 and rec.col_2 */
end loop;
elsif (p_parm1 is null) then
for rec in (select col_1, col_2
from table_a
where /*condition using p_parm2 */)
loop
/*Statements, use rec.col_1 and rec.col_2 */
end loop;
elsif (p_parm2 is null) then
for rec in (select col_1, col_2
from table_a
where /*condition using p_parm1 */)
loop
/*Statements, use rec.col_1 and rec.col_2 */
end loop;
else
for rec in (select col_1, col_2
from table_a
where /*condition using p_parm1 */
and /*condition using p_parm2 */)
loop
/*Statements, use rec.col_1 and rec.col_2 */
end loop;
end if;
end;
有没有办法让光标一次并指出如果没有提供参数则忽略哪些条件?
【问题讨论】:
标签: parameters plsql cursor