title: SQL Column Parameter Bind Variable with either or logic
body: <p>I apologize if the title is misleading.</p>
  
  <p>I'm trying to avoid using two different queries. With that in mind,</p>
  
  <p>I have the following sample query </p>
  
  <pre><code>  SELECT COUNT (*) COUNT,
           SUM (AMT) AS DED_AMT,
           SUM (SURCOST),
           SUM (DEALSUM),
           NVL (TO_CHAR (SUM (RETAIL)), 'N/A') AS RETAIL,
           MNFCID
      FROM (SELECT B.ID, B.CD, A.*
              FROM OUTPUTS_A A JOIN OUTPUTS_B B ON A.ID = B.ID
             WHERE B.ID = :ID AND B.CD = UPPER (:CD))
  GROUP BY ID;
  </code></pre>
  
  <p>that returns a result you can see in the first screenshot.<a href="https://i.stack.imgur.com/VIyrV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VIyrV.png" alt="enter image description here"></a></p>
  
  <p>Notice, I'm passing two bind variables in the query, :ID, :CD. They have to go together and that's why I'm using AND operator there.</p>
  
  <p>Sometimes, I have MFCID only and not :ID and :CD.</p>
  
  <p>This is the logic I'm thinking about. </p>
  
  <ol>
  <li><p>I would like to modify the query such a way that I should be able to pass MFCID as a bind variable. Let's say :mfcid is the variable I'm passing.</p></li>
  <li><p>If I have the values for :ID and :CD handy, I will pass those values and pass nothing for :mfcid. (Nothing in a sense that I won't pass anything. This field CAN'T be null)</p></li>
  <li><p>If I only have the value for :mfcid handy, I will pass that value and pass nothing for :ID and :CD. (Nothing in a sense that I won't pass anything. This field CAN'T be null) </p></li>
  </ol>
  
  <p>Either way it should return me the same result.</p>
  
  <p>I have tried putting it this way: <code>AND B.MNFCID = NVL(:MNFCID, B.MNFCID)</code> but it takes forever because it's always true if don't pass anything.</p>