2

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?

2 Answers 2

1

What about a WHERE clause like this:

 WHERE
       (in_parm_list = '*')
    OR (mineral = in_parm_list)
Sign up to request clarification or add additional context in comments.

Comments

0

Create a Ref cursor if you want to change the query dynamically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.