title: Oracle Substring a column for last index of character
body: <p>I am trying to do substring in Oracle using last index of a character '_'.</p>
  
  <p>Not able to get it rite. Please see the query which does a substring of second occurrence of "-". But it does not work if the string only has one occurrence of "-". </p>
  
  <pre><code>SELECT NVL(SUBSTR('TEMP_ABC', 0, INSTR('TEMP_ABC', '_',1,2)-1), 'TEMP_ABC') 
      FROM DUAL
  
  Result  - TEMP_ABC  
  Expected Result - TEMP
  
  SELECT NVL(SUBSTR('TEMP_ABC_XYZ', 0, INSTR('TEMP_ABC_XYZ', '_',1,2)-1), 'TEMP_ABC_XYZ') 
      FROM DUAL
  
  Result - TEMP_ABC
  Expected Result - TEMP_ABC
  </code></pre>
  
  <p>Any clue on what I am doing wrong here?</p>