Probabilmente stai cercando qualcosa del genere:
SELECT to_char( your_date_column, your_format_mask ) FROM your_table ORDER BY your_date_column
Nella lista di SELECT restituisci una stringa che rappresenta la data nel formato che preferisci, mentre nella clausola ORDER BY ordini per la data vera e propria. Usando le classiche tabelle EMP e DEPT:
SQL> ed Wrote file afiedt.buf 1 select to_char( hiredate, 'DD-MM-YYYY' ) 2 from emp, 3 dept 4 where emp.deptno = dept.deptno 5* order by hiredate SQL> / TO_CHAR(HI ---------- 17-12-1980 20-02-1981 22-02-1981 02-04-1981 01-05-1981 09-06-1981 08-09-1981 28-09-1981 17-11-1981 03-12-1981 03-12-1981 23-01-1982 19-04-1987 23-05-1987 14 rows selected.
Se mescoli anche un DISTINCT, sorgono problemi, perché Oracle non ha modo di sapere che la tua funzione (qui TO_CHAR) è una mappatura uno-a-uno. Due date distinte, per esempio 1 ottobre 2010 alle 10:15:15 e 1 ottobre 2010 alle 23:45:50, possono collassare nella stessa stringa, costringendo Oracle a scartare uno dei duplicati '01-10-2010' anche se le due date si ordinerebbero diversamente. La soluzione è annidare la query, applicare DISTINCT e riconvertire la stringa in data prima dell'ORDER BY:
SQL> ed Wrote file afiedt.buf 1 select hire_date_str 2 from ( 3 select distinct to_char( hiredate, 'DD-MM-YYYY' ) hire_date_str 4 from emp, 5 dept 6 where emp.deptno = dept.deptno 7 ) 8* order by to_date(hire_date_str,'DD-MM-YYYY') SQL> / HIRE_DATE_ ---------- 17-12-1980 20-02-1981 22-02-1981 02-04-1981 01-05-1981 09-06-1981 08-09-1981 28-09-1981 17-11-1981 03-12-1981 23-01-1982 19-04-1987 23-05-1987 13 rows selected.