• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Oracle cast()+PreparedStatement

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic