File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC - Oracle newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC - Oracle newbie question" Watch "JDBC - Oracle newbie question" New topic
Author

JDBC - Oracle newbie question

Nair Anoop
Ranch Hand

Joined: May 09, 2001
Posts: 68
Hi,
I am using JDBC to interact with an Oracle DB. I have fields of DateTime type in the DB. I need to write a few queries which require the hour or a particular month for a given date.
I know that MySQL has specific functions such as MONTH(Date) which gives the month from a quey and can be used directly in a sql statement.
Could some of you guys who have used Oracle tell me the corresponding functions in Oracle.
eg. I need a list of the number of customers who came in each hour. I have a DateTime field in the DB. Any help with this query ?
Thanks in advance,
Anoop
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

for the hour:
select to_char(date_column_name, 'HH12') from table where...
**note: 'HH12' = 1-12 or use 'HH24' = 0-24 hours

for the month:
select to_char(date_column_name, 'MM') from table where...
**note: 'MM'=two digit value or 'MONTH' = name of month padded with blanks to length of nine characters or 'MON' = 3 letter abbreviation of month.

Jamie
[This message has been edited by Jamie Robertson (edited November 30, 2001).]
Nair Anoop
Ranch Hand

Joined: May 09, 2001
Posts: 68
Jamie,
Thank you very much for your help.
-Anoop
 
 
subject: JDBC - Oracle newbie question