title: using oracle sql substr to get last digits
body: <p>I have a result of a query and am supposed to get the final digits of one column say 'term'</p>
  
  <pre><code>The value of column term can be like:
  'term'     'number' (output)
  ---------------------------
  xyz012         12
  xyz112         112
  xyz1           1
  xyz02          2
  xyz002         2
  xyz88          88
  </code></pre>
  
  <p>Note: Not limited to above scenario's but requirement being last 3 or less characters can be digit</p>
  
  <p>Function I used: <code>to_number(substr(term.name,-3))</code>
  (Initially I assumed the requirement as last 3 characters are always digit, But I was wrong)</p>
  
  <p>I am using to_number because if last 3 digits are '012' then number should be '12'
  But as one can see in some specific cases like 'xyz88', 'xyz1') would give a </p>
  
  <blockquote>
    <p>ORA-01722: invalid number</p>
  </blockquote>
  
  <p>How can I achieve this using substr or regexp_substr ?</p>
  
  <p>Did not explore regexp_substr much.</p>