R – Perl DBD::ODBC Issues with Oracle Date Formats

datetimedbdodbcoracleperl

I am using Perl's DBD::ODBC to connect to an Oracle database. However, an issue arises when I try to execute a select query using a date in the where clause. It seems this issue occurs because of the database's date format being DD-MON-RR (see DBD::ODBC::FAQ). Since I cannot change the database's settings, can anyone suggest a workaround?

Best Answer

The database's default date format only matters if you depend on it, which you should not in general. You can:

1) Specify the format of the date in your query:

select *
from news
where news_date = to_date ('01-DEC-2009','DD-MON-RRRR');

2) Use the ANSI standard for date literals:

select *
from news
where news_date = DATE '2009-12-01';
Related Topic