title: Optional Parameters as Condition in a Cursor (PL/SQL)
body: <p>I have a function/procedure that takes optional parameters. If provided, I need to use the parameters as conditions for cursors. If not provided, then I don't want that condition.</p>
  
  <p>Here is a very simplified version of what I've come up with:</p>
  
  <pre><code>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 &amp;&amp; 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;
  </code></pre>
  
  <p>Is there a way to have the Cursor once and indicate which conditions to ignore if parameters aren't provided?</p>