This SQL Server Post was quite helpful. I'm using PL/SQL on Oracle 11g. I want cursor to accept both v_parm1 and v_parm2.
Here's what I've done.
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;
If I use v_parm1 then return just 1-TALC.
If I use v_parm2 then return all 4 rows.
Question: How can I write cursor to accept either v_parm1 or v_parm2?