Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a query to select last 5 vehicle are recently reported. which is stored in "VEHICLE_IN" table.

SELECT R.REG_NO FROM
   (SELECT G.REG_NO FROM VEHICLE_IN G
    INNER JOIN VEHICLE_MASTER M ON G.REG_NO=M.REG_NO
    WHERE to_date((IN_DATE||' '||IN_TIME),'YYYY-MM-DD HH24:MI') >= (SYSDATE-30/1440)
    AND M.VEHICLE_STAND='STAND1'
    ORDER BY G.IN_DATE DESC, G.IN_TIME DESC) R
   WHERE ROWNUM <= 5
   GROUP BY R.REG_NO ;


[Record format (VARCHAR2(20)): IN_DATE : '2016-03-21'; IN_TIME: '18:27']

The query returns an error

01861-literal-does-not-match-format-string

But the condition works in some other query.

Anybody please help me to find out the mistake..

What I have tried:

I have increase size of both IN_date and In_time fields to 50. Still error occurred. But
SELECT REG_NO,IN_DATE,IN_TIME FROM VEHICLE_IN WHERE TO_DATE((IN_DATE||' '||IN_TIME ),'YYYY-MM-DD HH24:MI') >= (SYSDATE-30/1440)  

this query working good.
Posted
Comments
phil.o 23-Mar-16 5:15am    
Why using two varchar fields for storing date and time instead of using the built-in datetime type(s)? This is a terrible practice, and the reason why you have this problem in the first place.
Herman<T>.Instance 23-Mar-16 5:27am    
Use SQlProfilerExpress when executing the record. It will give more detail regarding this error
vpinraj 23-Mar-16 6:11am    
Thank you for your valuable reply sir
vpinraj 23-Mar-16 5:34am    
@Phil.o thank you for your valuable reply sir, But its works in second query. why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900