Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert Date with to_char() in a select statement

 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me what the correct syntax is for doing this I need to
format the date for my app, but the syntax is wrong I get a Invalid column name exception.

"SELECT product_id, product_type_id, name, description, long_description, to_char(active_from,'dd/mm/yyyy'), to_char(active_to,'dd/mm/yyyy') from product WHERE product_id = " + prodID + " and product_type_id = " + prodTypeID;

This works fine when when I run it in sql. So I think JDBC does not like it.

I'm using Oracle 8

Reg

[ January 18, 2005: Message edited by: Reggie McDougal ]
[ January 18, 2005: Message edited by: Reggie McDougal ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reggie,

give alias to columns on which you are applying
to_char() and make your sql query as

"SELECT product_id, product_type_id, name, description, long_description, to_char(active_from,'dd/mm/yyyy') active_from, to_char(active_to,'dd/mm/yyyy') active_to from product WHERE product_id = " + prodID + " and product_type_id = " + prodTypeID;


then your JDBC will like it


thanks
Shailesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic