Why is there a discrepancy between ActiveRecord SQL and PL / SQL Developer SQL?
I have a select statement in Oracle PL / SQL Developer that retrieves values based on a date:
select * from <table> where to_date(create_date) = to_date('20090506', 'YYYYMMDD')
where create_date
has a date of type Oracle. This returns a non-empty set as it should. However, in ActiveRecord:
<Table>.find_by_sql("select * from <table> where to_date(create_date) = to_date('20090506', 'YYYYMMDD')")
returns no strings, which is not correct. I suspect it has something to do with how ActiveRecord handles Time / Date / DateTime objects.
Any ideas? Thanks to
a source to share
Given your own hack and the column name create-DATE, I suspect the creation date is a DATE column. Oracle is friendly enough not to raise an error when you do to_date on a date column, but it would be better if this would cause an error. So, the correct solution would be (both in ORACLE !, and in ActiveRecord):
select * from <table> where create_date = to_date('20090506', 'YYYYMMDD')
In short: don't use to_date () on a date column.