Home » SQL & PL/SQL » SQL & PL/SQL » How to get the Months (Jan to Dec) of the year through SQL Query?
How to get the Months (Jan to Dec) of the year through SQL Query? [message #221655] Tue, 27 February 2007 23:18 Go to next message
fazal_haq2001
Messages: 35
Registered: July 2006
Location: India
Member
Hi friends,
I m trying to retrieve the months of the year through sql query..I didnt find the solution..Plz help to sort out this issue..

Regards,
Fazal...
Re: How to get the Months (Jan to Dec) of the year through SQL Query? [message #221690 is a reply to message #221655] Wed, 28 February 2007 01:33 Go to previous messageGo to next message
shahnazurs
Messages: 240
Registered: June 2005
Location: India
Senior Member
Hi Fazal,
Could you clear in your question?

you can use to_char function to do this. Tell me how you want to display your o/p?

Thanks,
Shahnaz.
Re: How to get the Months (Jan to Dec) of the year through SQL Query? [message #221693 is a reply to message #221690] Wed, 28 February 2007 01:47 Go to previous messageGo to next message
fazal_haq2001
Messages: 35
Registered: July 2006
Location: India
Member
Thank u for ur swift response..
I want the output from sql query like

jan
Feb
Mar
......
Dec

I want this through a single query
I can get a single month through to_char..But i want all months..


Regards,
Fazal...
Re: How to get the Months (Jan to Dec) of the year through SQL Query? [message #221702 is a reply to message #221693] Wed, 28 February 2007 02:13 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
SQL> SELECT the_month
  2  FROM ( SELECT TO_CHAR( ADD_MONTHS( TRUNC(SYSDATE,'year')
  3                                   , LEVEL-1
  4                                   )
  5                       , 'Mon'
  6                       ) the_month
  7         FROM   dual
  8         CONNECT BY level <= 12
  9       )
 10  /

THE
---
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec

12 rows selected.

SQL>


MHE

Moved to newbies: this is no expert question.
Re: How to get the Months (Jan to Dec) of the year through SQL Query? [message #221705 is a reply to message #221702] Wed, 28 February 2007 02:18 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
You could even use the brute force solution:
SELECT month FROM (
SELECT 'Jan' Month from dual union all
SELECT 'Feb' Month from dual union all
SELECT 'Mar' Month from dual union all
SELECT 'Apr' Month from dual union all
SELECT 'May' Month from dual union all
SELECT 'Jun' Month from dual union all
SELECT 'Jul' Month from dual union all
SELECT 'Aug' Month from dual union all
SELECT 'Sep' Month from dual union all
SELECT 'Oct' Month from dual union all
SELECT 'Nov' Month from dual union all
SELECT 'Dec' Month from dual);

It's not pretty, but it works.
Re: How to get the Months (Jan to Dec) of the year through SQL Query? [message #221708 is a reply to message #221705] Wed, 28 February 2007 02:32 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Laughing Good one!

MHE

[Updated on: Wed, 28 February 2007 02:32]

Report message to a moderator

Re: How to get the Months (Jan to Dec) of the year through SQL Query? [message #221709 is a reply to message #221705] Wed, 28 February 2007 02:36 Go to previous message
fazal_haq2001
Messages: 35
Registered: July 2006
Location: India
Member
its working...
Thanks a lot..

Regards,
Fazal...
Previous Topic: Error in Query
Next Topic: Date format conversion.
Goto Forum:
  


Current Time: Sat Dec 03 18:19:56 CST 2016

Total time taken to generate the page: 0.08930 seconds