Oracle SQL - DATE greater than statement
As your query string is a literal, and assuming your dates are properly stored as DATE
you should use date literals:
SELECT * FROM OrderArchiveWHERE OrderDate <= DATE '2015-12-31'
If you want to use TO_DATE
(because, for example, your query value is not a literal), I suggest you to explicitly set the NLS_DATE_LANGUAGE parameter as you are using US abbreviated month names. That way, it won't break on some localized Oracle Installation:
SELECT * FROM OrderArchiveWHERE OrderDate <= to_date('31 Dec 2014', 'DD MON YYYY', 'NLS_DATE_LANGUAGE = American');
You need to convert the string to date using the to_date()
function
SELECT * FROM OrderArchiveWHERE OrderDate <= to_date('31-Dec-2014','DD-MON-YYYY');
OR
SELECT * FROM OrderArchiveWHERE OrderDate <= to_date('31 Dec 2014','DD MON YYYY');
OR
SELECT * FROM OrderArchiveWHERE OrderDate <= to_date('2014-12-31','yyyy-MM-dd');
This will work only if OrderDate
is stored in Date format
. If it is Varchar
you should apply to_date()
func on that column also like
SELECT * FROM OrderArchive WHERE to_date(OrderDate,'yyyy-Mm-dd') <= to_date('2014-12-31','yyyy-MM-dd');
you have to use the To_Date() function to convert the string to date !http://www.techonthenet.com/oracle/functions/to_date.php