2
This SQL Server Post非常有幫助。我在Oracle 11g上使用PL/SQL。我希望光標同時接受v_parm1
和v_parm2
。如何使用參數獲取所有非空行?
這是我所做的。
DECLARE
v_parm1 varchar2(50) := 'TALC';
v_parm2 varchar2(50) := '*';
cursor cursor_with_parms(in_parm_list varchar2)
is
with mohs_scale as
(select '1' as moh_val , 'TALC' as mineral from dual union all
select '2' as moh_val , 'GYPS' as mineral from dual union all
select '3' as moh_val , 'CALC' as mineral from dual union all
select '4' as moh_val , 'FLUO' as mineral from dual)
select moh_val,
mineral
from mohs_scale
where
case in_parm_list when '*' then mineral is not null
else mineral = in_parm_list
end;
BEGIN
for rock in cursor_with_parms(v_parm1) loop
dbms_output.put_line(rock.moh_val || ' ' || rock.mineral);
end loop;
END;
如果我使用v_parm1
,那麼只返回1-TALC。 如果我使用v_parm2
,則返回所有4行。
問題:如何寫光標接受v_parm1
或v_parm2
?