• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle cast()+PreparedStatement

 
Gabor Beres
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a SQL query: SELECT * FROM mytable WHERE mydate = :mydate

mydate is a TIMESTAMP, but i need to cast it to DATE using Oracle function cast(): SELECT * FROM mytable WHERE mydate = cast(:mydate as DATE)

Unfortunatelly i'm using PreparedStatements, so i set the parameter via method setTimestamp()

Is it possible to do the cast anyway?

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be - you are still inserting a binding variable. Does that not work? What error does it give you?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important question is - why do you need to cast? It can be problematic, as TIMESTAMP may contain millisecond (and possibly timezone), while DATE cannot. The cast will strip off this information if present and therefore might produce value different from what you set via setTimestamp(). If it happened, it would alter the results of your query.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic