title: Oracle Sum Based On Condition
body: <p>SQL first so I can reference it lower:</p>
  
  <pre><code>SELECT ID, 
         SUM(length(substr(DATA_STRING, instr(DATA_STRING,'P')+1))) 
  FROM DATA P, PLC PP 
  WHERE P.ID = PP.ID 
    AND instr(DATA_STRING, 'F') = 0 
  GROUP BY ID
  </code></pre>
  
  <p>The function above looks for the P in each data string and counts up how many characters are in the string.</p>
  
  <p>So my problem is thus, I have two conditions that can occur, one where the data string could contain the P as in above, or when it contains a F. I need to be able to check for both and then sum up the total. The issue with the above is that I sum in a 0 if that condition when the string has an F occurs. </p>
  
  <p>I almost need the equivalent of SUMIF in Excel so that I could say if when I search for P it's 0, then look for the F and add in that length and vice versa.</p>
  
  <p>Please let me know if you have suggestions!</p>