Im trying to run this below query but its seems to be error
For those data types are varchar
Query
select *
from RP_REPORT_TEMP
where to_char(START_DATE,'FM DD YYYY HH24:MI:SS AM')
>= 'May 01 2016 00:00:00'
and to_char(END_DATE,'FM DD YYYY HH24:MI:SS PM')
<= 'May 31 2016 11:59:00'
and lower(rid) like '%a001%'
order by CAST(cid as INTEGER) asc
Table
|RID |START_DATE |END_DATE |
|--------------------|-------------------------- |-----------------------------|
|A001 |May 1 2016 12:00:00:000AM |May 31 2016 12:00:00:000PM |
|A001 |May 1 2016 12:00:00:000AM |May 31 2016 12:00:00:000PM |
|A001 |May 1 2016 12:00:00:000AM |May 31 2016 12:00:00:000PM |
While i tried to execute this query. Query return some error. How can i fix this ?
Error
SQL Error [1722] [42000]: ORA-01722: invalid number
java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
TO_CHAR()does not exist in either DBMS. I've assumed it was an error and removed them. If you're actually looking for a cross-DBMS method to manipulate dates please edit the question.START_DATE,END_DATE,CIDHH24in your OP and use proper spacing with meridiams indicatorsvarcharcolumns. Just don't.TO_DATE( 'January 15, 1989, 11:00 A.M.', 'Month dd, YYYY, HH:MI A.M.', 'NLS_DATE_LANGUAGE = American')That one is not usingHH24plus is specifying the date language (hopefully your defaullt date language is American). Check this docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm . Anyways since you table fields are varchar, I recommand they be stored in proper date format (though varchar) then do a to_date to_date comparison (see Avi answer below if you want to use HH24 or Alvaro ansswer if not using HH24 )