Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Connect by level query is taking too long time to run

748467Jan 26 2010 — edited Jan 29 2010
Hello,

I have a query that returns quarters (YYYYQ) of a begin- and enddate within a specific id, that is built with a connect by level clause, but the query is running to long. I have used explain plan to see what the query is doing, but no silly things to see, just a full table scan, with low costs.

This is the query:

select to_char(add_months( cpj.crpj_start_date,3*(level - 1)),'YYYYQ') as sales_quarter
, cpj.crpj_id as crpj_id
from mv_gen_cra_projects cpj
where cpj.crpj_start_date >= to_date('01/01/2009','mm/dd/yyyy')
and cpj.crpj_start_date <= cpj.crpj_end_date
and cpj.crpj_routing_type = 'A'
and ( cpj.crpj_multi_artist_ind = 'N'
or cpj.crpj_multi_artist_ind is null)
connect by level <= 1 + ceil(months_between(cpj.crpj_end_date,cpj.crpj_start_date)/3);

The result have to be like this:

SALES_QUARTER CRPJ_ID
----------------------- -----------
20091 100
20092 100
20093 100
20094 100
20101 100
20102 100

Can anyone help me out with this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 26 2010
Added on Jan 26 2010
8 comments
2,988 views