Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 931277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:28:24+00:00 2026-05-15T20:28:24+00:00

I am running a query that returns me a collection of date objects for

  • 0

I am running a query that returns me a collection of date objects for months between a certain date range. The query works fine, but is very slow (~2 seconds on my local machine, ~30 in our corporate development environment). Here it is:

SELECT ADD_MONTHS(TO_DATE('200804', 'YYYYMM'), -1+rownum) AS MONTH
FROM all_objects
WHERE ADD_MONTHS(TO_DATE('200804', 'YYYYMM'), -1+rownum) <= TO_DATE('200805', 'YYYYMM')

Currently, it will only return one month, but if you extend the second date string, it returns more.

I have two questions. First, why does this run so slow? I know Oracle functions really slow down a query, but this takes about 30 seconds on a development machine at my work.

The second, and more puzzling question: why does the runtime shorten to a fraction of a second when you extend the range to, say, ‘201805’? I would think that a greater range would take longer. It seems to be the opposite effect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:28:24+00:00Added an answer on May 15, 2026 at 8:28 pm

    There is no need to use inline views and I see too much date functions being used.
    If you skip all that, this remains:

    SQL> var START_YM varchar2(6)
    SQL> var END_YM varchar2(6)
    SQL> exec :START_YM := '200804'; :END_YM := '201805'
    
    PL/SQL procedure successfully completed.
    
    SQL>  select add_months(to_date(:START_YM,'yyyymm'),level-1) m
      2     from dual
      3  connect by level <= months_between(to_date(:END_YM,'yyyymm'),to_date(:START_YM,'yyyymm'))+1
      4  /
    
    M
    -------------------
    01-04-2008 00:00:00
    01-05-2008 00:00:00
    01-06-2008 00:00:00
    <... 116 rows skipped ...>
    01-03-2018 00:00:00
    01-04-2018 00:00:00
    01-05-2018 00:00:00
    
    122 rows selected.
    

    Which looks even easier …

    Regards,
    Rob.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running a query against a providex database that we use in MAS
I currently have the query running on Postgres: SELECT * FROM addenda.users WHERE users.username
My Server is located in US and I am running a query against it.
I'm running an SQL query against a mainframe DB2 database using the OdbcDataReader class
I'm running the following query in Hypersonic DB (HSQLDB): SELECT (CASE foo WHEN 'a'
I'm having trouble running a complex query against our company LDAP server. I'm using
Is there any way to use AppleScript (or something else) to query currently running
After running a insert or update query against a SQLServer 2005 database, under what
I am running oracle and have a query which pulls some results from the
Running a rails site right now using SQLite3. About once every 500 requests or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.