title: Oracle : Sort a list on second word in SQL Query?
body: <p>In Oracle, how do i sort a value for eg: <code>Name</code> in SQL using its second word. Looks a bit tricky to me. For eg: If in a table i have the names as below:</p>
  
  <p>I have a list of objects which i want to sort on basis of name. I have done coding where it does get sorted on basis of name but i have a slight different requirement.</p>
  
  <p>The names are for Example:</p>
  
  <pre><code>Bull AMP
  Cat DEF
  Dog AMP
  Frog STR
  Zebra DEF
  </code></pre>
  
  <p>I want the list to be :</p>
  
  <pre><code>Bull AMP
  Dog AMP
  Cat DEF
  Zebra DEF
  Frog STR
  </code></pre>
  
  <p>To be sorted by second word.</p>
  
  <p>I tried the below query but it didnt seem to work.</p>
  
  <pre><code>SELECT NAME, 
    SUBSTR(NAME, INSTR(' ',NAME), 
    LENGTH(NAME) - INSTR(' ',NAME) +2) AS word2
  FROM animal_master
  ORDER BY SUBSTR(NAME,INSTR(' ',NAME), LENGTH(NAME) - INSTR(' ',NAME) +2) asc;
  </code></pre>
  
  <p>Can anyone please guide whats wrong.</p>