If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Month value in SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-03, 17:39
chinna16 chinna16 is offline
Registered User
 
Join Date: Sep 2003
Posts: 9
Month value in SQL

Hi all

Does anyone know how to get the month field from a date in a SQL statement? I am using Oracle 8.0

There is a field called "birth_date" in my table and I have to print the number of records group by month as follows:

Month Count
------- -------
1 45
2 187
3 18
. ..
. ..
. ..
etc

I need the month value in 1-12 format. Please help..

-Chinna
Reply With Quote
  #2 (permalink)  
Old 12-22-03, 18:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
select month(birth_date),count(*)
from yourtable
group by month(birth_date)


rudy
Reply With Quote
  #3 (permalink)  
Old 12-24-03, 04:08
hxshxs hxshxs is offline
Registered User
 
Join Date: Dec 2003
Posts: 3
There is not "month" function in Oracle!
that shoulde be:
select to_char(brith_day,'mm'),count(*) from yourtable group by to_char(brith_day,'mm')
Reply With Quote
  #4 (permalink)  
Old 12-24-03, 06:00
edwinjames edwinjames is offline
Registered User
 
Join Date: Dec 2003
Posts: 74
select to_char(sysdate,'MON') from dual;

will return today's month
Reply With Quote
  #5 (permalink)  
Old 12-24-03, 06:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
MONTH() is ANSI/ISO standard sql

my apologies, Chinna, i overlooked the fact that you said oracle 8

oracle corp, in its infinite wisdom, apparently did not begin supporting standard sql until release 9

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On