-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Query using Date fails !
PostPosted: Wed Mar 18, 2009 12:32 pm 
Newbie

Joined: Wed Feb 14, 2007 4:49 am
Posts: 7
Hi all!
I'm desperately trying to execute a query which has in its WHERE condition a Date field.

Since the Date field contains dd/mm/yyyy hh:mm:ss I need to issue a trunc:
this is the exact SQL that works from Sql plus:

Code:
select taskId FROM tasklist
where trunc(begin_date) = to_date( '01-01-2004','dd-mm-yyyy')


This is my EJB QL query:

Code:
SELECT taskId from TaskList WHERE trunc(BEGIN_DATE)= '2004-01-01'


but this issues a "Caused by: java.sql.SQLException: ORA-01861: literal does not match format string"


Code:
SELECT taskId from TaskList WHERE trunc(BEGIN_DATE)= '01/01/2004'

Still the same problem.....:-(

I'm using Entity Beans 3.0 JPA (JBoss Application server). Unfortunately I couldn't find anything on EJB 3.0 related documents so I'm looking here for help.....

thanks alot
frank


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 12:50 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
I think the date format setting is different while executing via SQL Plus and executing via Hibernate. Try setting the date

alter session set nls_date_format=<format you want> and then execute the other Query.

Hope this helps,
Latha.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 1:04 pm 
Beginner
Beginner

Joined: Wed Oct 03, 2007 4:10 am
Posts: 46
The select you want to execute is:


SELECT taskId from TaskList WHERE to_char(BEGIN_DATE,'dd/mm/yyyy')= '01/01/2004'


Top
 Profile  
 
 Post subject: it worked !!!
PostPosted: Thu Mar 19, 2009 5:56 am 
Newbie

Joined: Wed Feb 14, 2007 4:49 am
Posts: 7
Thanks a lot ! to_char was the right function !
regards
frank


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.