select count(*) from tabella where start_date > to_date('23-09-2010 18:00:00','DD-MM-YYYY HH24:MI:SS') order by end_date desc
Se invece voglio fare un confronto di stringhe allora devo convertire in stringa (to_char) la data che sto confrontando. Siccome è un confronto di stringhe allora la data deve essere espressa con annno mese e giorno (YYYYMMDD) altrimenti l’ordinamento non viene mantenuto.
select count(*) from tabella where to_char(start_date,'YYYYMMDD HH24:MI:SS') > '20100923 18:00:00' order by end_date desc
Altri esempi di query:
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> SET LINESIZE 30 SQL> select to_char (sysdate,'YYYY-MM-DD HH24:MI:SS') as data from dual; DATA ------------------- 2010-09-30 17:11:34 SQL> select to_char (sysdate,'YYYY-MON-DD HH24:MI:SS') as data from dual; DATA -------------------- 2010-SEP-30 17:22:21 SQL> alter session set NLS_LANGUAGE=ITALIAN; Session altered. SQL> select to_char (sysdate,'YYYY-MON-DD HH24:MI:SS') as data from dual; DATA -------------------- 2010-SET-30 17:22:31