title: Oracle Order by - Function Based (dense_rank)
body: <p>I have a table that has the following 4 columns with some example data</p>
  
  <pre><code>Aisle | Rack | Level | Position
    1        1       1         1
    1        2       1         2
    2        1       1         1
    2        2       1         1
    2        3       1         1
    3        1       1         1
    3        2       1         1
  </code></pre>
  
  <p>I wish to write a single query that can Sort records using the following</p>
  
  <ul>
  <li><p>First by Aisle (Ascending)</p></li>
  <li><p>Then by Rack (Ascending for one Aisle and Descending for the next and
  so on. . .This is the part that I can't seem to figure out if it can
  be achieved in Oracle)</p></li>
  <li><p>Then by Level (Ascending)</p></li>
  <li><p>Then by Position (Ascending)</p></li>
  </ul>
  
  <p>So the resulting ordered rows will be as follows</p>
  
  <pre><code> Aisle | Rack | Level | Position
    1        1       1         1
    1        2       1         2
    2        3       1         1
    2        2       1         1
    2        1       1         1
    3        1       1         1
    3        2       1         1
  </code></pre>
  
  <p>We worked out the following Order by Clause</p>
  
  <pre><code>order by aisle,
        (case when mod(dense_rank() over (order by aisle), 2) = 1 then rack else - rack
         end),
        level,
        position
  </code></pre>
  
  <p>But, I am getting an error <strong>"ORA-00932: inconsistent datatypes: expected CHAR got NUMBER"</strong> when I execute the query. The columns are all VARCHAR2 type. </p>
  
  <p>What could I do to make it work?         </p>