title: How to skip condition check in where clause if parameter value is null or blank?
body: <p>Need a small help. I am working on a stored procedure call which runs a select. (I cant put in the actual select due to business constraints but I will give you  a dummy scenario.)</p>
  
  <p>Here is a stored procedure:</p>
  
  <pre><code>Procedure checkData (name IN VARCHAR2, vehicle IN VARCHAR2, retval OUT VARCHAR2, retdata OUT returnData)
  </code></pre>
  
  <p>The select inside it gets values from a text box field which is used for search. The select is like this,</p>
  
  <pre><code>select *
  from myTable tab
  WHERE tab.vehicle = vehicle
    AND tab.name = name
  </code></pre>
  
  <p>Now what the issue is when the user specifies only one value out of the 2 mentioned above, the search fails as it tries to check the details based on <code>AND</code> condition</p>
  
  <p>For example, if user provides only vehicle value, lets say <code>'BMW'</code> then the result should contain all the entries for vehicle. But what happens is as the user has not provided name value, it takes it as <code>''</code> or null and the query doesn't return anything as it doesn't find any data matching <code>name = ''</code> condition.</p>
  
  <p>So I tried below,</p>
  
  <pre><code>select *
  from myTable tab
  WHERE tab.vehicle = vehicle
  AND IF name IS NOT NULL OR name != ''
  tab.name = name
  </code></pre>
  
  <p>But it says, </p>
  
  <blockquote>
    <p>ORA-00920:invalid relational operator.</p>
  </blockquote>
  
  <p>So what can I do to skip the second check if the value for name is either null or ''. In that specific case, I simply want to skip the second check and return result based on vehicle values only.</p>
  
  <p>I can't use <code>OR</code> condition because I will need to get exact matches too when both the parameters are available. I am using Oracle DB.</p>
  
  <p>Any help is appreciated. Thanks a lot.</p>