Home » SQL & PL/SQL » SQL & PL/SQL » List of the months according to current date
List of the months according to current date [message #340542] Wed, 13 August 2008 04:29 Go to next message
mudabbir
Messages: 235
Registered: April 2006
Location: Kuwait
Senior Member

Hi All,

From the first date of the current year till current date , how can we know the list of the months.

If I execute the query the result should be as below which includes current month also

Months
---------
January
February
March
April
May
June
July
August

Best Regards,
Mudabbir
Re: List of the months according to current date [message #340548 is a reply to message #340542] Wed, 13 August 2008 04:38 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Default question: What did you try so far?
Use a row generator, generating a number of rows, equal to today's month-number.
Re: List of the months according to current date [message #340552 is a reply to message #340548] Wed, 13 August 2008 04:57 Go to previous messageGo to next message
mudabbir
Messages: 235
Registered: April 2006
Location: Kuwait
Senior Member

Hi Frank,

I am trying using row generators,but not being successfull yet..

Mudabbir
Re: List of the months according to current date [message #340553 is a reply to message #340542] Wed, 13 August 2008 04:59 Go to previous messageGo to next message
Cthulhu
Messages: 381
Registered: September 2006
Location: UK
Senior Member
Something like:

select to_char(add_months('01-jan-08', level-1), 'Mon')
from dual
connect by level  <= months_between(sysdate, '01-jan-08')+1
order by add_months('01-jan-08', level-1)
Re: List of the months according to current date [message #340554 is a reply to message #340548] Wed, 13 August 2008 04:59 Go to previous messageGo to next message
Olivia
Messages: 519
Registered: June 2008
Senior Member
In Oracle 9i,
SELECT Month from (
select to_char(add_months('01-jan-08', level), 'Mon') Month
from dual
connect by level  <= months_between(sysdate, '01-jan-08'))
order by add_months('01-jan-08', level)
/


Regards,
Oli

[Updated on: Wed, 13 August 2008 05:05]

Report message to a moderator

Re: List of the months according to current date [message #340556 is a reply to message #340553] Wed, 13 August 2008 05:05 Go to previous messageGo to next message
mudabbir
Messages: 235
Registered: April 2006
Location: Kuwait
Senior Member

Thanks Neal, You were very precise,

I modified the code however a bit to suit my needs. As follows

select to_char(add_months(TRUNC(SYSDATE,'Y'), level-1), 'Month')
from dual
connect by level  <= months_between(sysdate, TRUNC(SYSDATE,'Y'))+1
order by add_months(TRUNC(SYSDATE,'Y'), level-1)


Thanks all for the Help.
Re: List of the months according to current date [message #340557 is a reply to message #340554] Wed, 13 August 2008 05:06 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Don't put solution only hint or clue as requested in OraFAQ Forum Guide, "Responding to Posts" section:
Quote:
When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.


@Olivia,
You're certainly unable or unwilling to read and follow guidelines.

Regards
Michel
Re: List of the months according to current date [message #340602 is a reply to message #340557] Wed, 13 August 2008 06:39 Go to previous messageGo to next message
Olivia
Messages: 519
Registered: June 2008
Senior Member
Michel Cadot wrote on Wed, 13 August 2008 05:06
Don't put solution only hint or clue as requested in OraFAQ Forum Guide, "Responding to Posts" section:
Quote:
When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.


@Olivia,
You're certainly unable or unwilling to read and follow guidelines.

Regards
Michel




Sorry Michel...
Initially I was trying to provide some hint to OP.I still remember Frank's advice. But the moment I try to give the solution,it was already been posted. I just made correction to the query.

I didnt know that showing the correct path is an offence!

It can be done using ROWNUM also.
Use SYSDATE+ROWNUM  ..Connect by level <= date diff



Regards,
Olivia

[Updated on: Wed, 13 August 2008 06:43]

Report message to a moderator

Re: List of the months according to current date [message #340610 is a reply to message #340602] Wed, 13 August 2008 07:22 Go to previous message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
I didnt know that showing the correct path is an offence!

Showing the solution is not an offense, it is just not the way this site chose to work.
Showing the correct path/way is what we want.
And with 220 posts you should know it. I just can't imagine you didn't.
In addition, my post was not just for you but for Cthulhu as well.

By the way, your solutions are not correct as '01-jan-08' is a string and not a date.

Regards
Michel
Previous Topic: Continous Execution after Exception Handling
Next Topic: explain plan for mview...
Goto Forum:
  


Current Time: Thu Dec 08 22:07:44 CST 2016

Total time taken to generate the page: 0.13377 seconds