How to use CONNECT BY LEVEL to get this result?

Hi all,
my DB version is 10gR2.
here is the table and the data:
create table t (from_dt date, to_dt date, eno varchar2(2), deptno varchar2(10));
insert into T values (TO_DATE('2010-01-01','yyyy-mm-dd'),TO_DATE('2010-04-30','yyyy-mm-dd'),'A','DEPTA');
insert into T valueS (TO_DATE('2010-05-01','yyyy-mm-dd'),TO_DATE('2010-12-31','yyyy-mm-dd'),'A','DEPTB');
insert into T values (TO_DATE('2010-01-01','yyyy-mm-dd'),TO_DATE('2010-06-30','yyyy-mm-dd'),'B','DEPTA');
insert into T valueS (TO_DATE('2010-07-01','yyyy-mm-dd'),TO_DATE('2010-12-31','yyyy-mm-dd'),'B','DEPTB');
from_dt       to_dt           ENO   DEPTNO
2010-01-01 2010-04-30  A     DEPTA
2010-05-01 2010-12-31  A     DEPTB
2010-01-01 2010-06-30  B     DEPTA
2010-07-01 2010-12-31  B     DEPTBHere is the result I want:
MONTH    ENO   DEPTNO
2010-01    A      DEPTA
2010-02    A      DEPTA
2010-03    A      DEPTA
2010-04    A      DEPTA
2010-05    A      DEPTB
...............Here is what I came up with:
select distinct ADD_MONTHS(TRUNC(FROM_DT,'MON'),level-1) as MONTHS,
       ENO,
       DEPTNO
from (
    select FROM_DT, TO_DT, ENO, DEPTNO, ROUND(MONTHS_BETWEEN(TO_DT, FROM_DT)) as BET from T
) connect by level<=BET
order by eno, deptno,months ;the problem with this is that, many duplicate rows are generated if I remove DISTINCT from the sql.
and I don`t know how that happens? How CONNECT BY LEVEL, returns me so many duplicate rows?
Anyone have any idea about this?
And is there any other way to do this as well?
Thanks

In this case,model clause is one way :-)
with t(from_dt,to_dt,eno,deptno) as(
select date '2010-01-01',date '2010-04-30','A','DEPTA' from dual union
select date '2010-05-01',date '2010-12-31','A','DEPTB' from dual union
select date '2010-01-01',date '2010-06-30','B','DEPTA' from dual union
select date '2010-07-01',date '2010-12-31','B','DEPTB' from dual)
select *
  from t
model
partition by(RowNum as PID)
dimension by(0 as soeji)
measures(from_dt,to_dt,eno,deptno)
rules iterate(100)
UNTIL (add_months(from_dt[0],ITERATION_NUMBER+1) > to_dt[0])
(from_dt[ITERATION_NUMBER]=add_months(from_dt[0],ITERATION_NUMBER),
eno[ITERATION_NUMBER]=eno[0],
deptno[ITERATION_NUMBER]=deptno[0])
order by eno,from_dt;
PID  SOEJI  FROM_DT   TO_DT     E  DEPTN
  1      0  10-01-01  10-04-30  A  DEPTA
  1      1  10-02-01  null      A  DEPTA
  1      2  10-03-01  null      A  DEPTA
  1      3  10-04-01  null      A  DEPTA
  3      0  10-05-01  10-12-31  A  DEPTB
  3      1  10-06-01  null      A  DEPTB
  3      2  10-07-01  null      A  DEPTB
  3      3  10-08-01  null      A  DEPTB
  3      4  10-09-01  null      A  DEPTB
  3      5  10-10-01  null      A  DEPTB
  3      6  10-11-01  null      A  DEPTB
  3      7  10-12-01  null      A  DEPTB
  2      0  10-01-01  10-06-30  B  DEPTA
  2      1  10-02-01  null      B  DEPTA
  2      2  10-03-01  null      B  DEPTA
  2      3  10-04-01  null      B  DEPTA
  2      4  10-05-01  null      B  DEPTA
  2      5  10-06-01  null      B  DEPTA
  4      0  10-07-01  10-12-31  B  DEPTB
  4      1  10-08-01  null      B  DEPTB
  4      2  10-09-01  null      B  DEPTB
  4      3  10-10-01  null      B  DEPTB
  4      4  10-11-01  null      B  DEPTB
  4      5  10-12-01  null      B  DEPTB

Similar Messages

  • I recieved an Adobe Master Collection License number from my school (Stevens Institute of Technology) and I can't figure out how to use it in order to get the product. I've created a username and that's as far as I've gotten.

    I recieved an Adobe Master Collection License number from my school (Stevens Institute of Technology) and I can't figure out how to use it in order to get the product. I've created a username and that's as far as I've gotten. I need to download the product and I can't figure out where to begin.

    Ask someone at your school... Do you have a Cloud redemption code, or a CS6 serial number?
    If Cloud, Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html and
    http://www.adobe.com/products/creativecloud/faq.html
    http://helpx.adobe.com/creative-cloud/help/install-apps.html to install or uninstall
    http://forums.adobe.com/community/download_install_setup/creative_cloud_faq
    What it is http://helpx.adobe.com/creative-cloud/help/creative-cloud-desktop.html
    Cloud Getting Started https://helpx.adobe.com/creative-cloud.html
    If CS6, download at Other downloads and enter your serial number when prompted
    Again... your 1st resource is your school

  • How to use connection pooliing in welogic server

    How to use connection pooliing in welogic server

    Ummmm, once you have an open connection to something, you add it to a pool so the next time you need to connect to it, you don't have to redo all of the overhead of creating the connection.
    :-)

  • How to use Connection Pool in ADF ear file creaion from jDev 10.1.3

    Hi,
    We are developing big application in ADF with 10 different modules. We are creating ear file with data source setting.
    How to use connection pool while creating ear file from jDev. Connection pool is alreday created in Application Server 10g.
    What all the setting we need do to make use of connection pool while creating ear file jDev.
    Thanks

    User,
    If you are using ADF Business Components, you can right-click each application module, select "configurations" and edit the configuration you are using. On the initial page of the configuration dialog, you can specify to use either a JDBC URL or a Datasource - you just need to choose Datasource and then provide the name by which to access it.
    John

  • How to use connection pool of datasource to make applications run faster?

    Hi, erveryone
    I prepare to implement a servlet that access database and do sync with client.
    When I access database, I would like to configure a datasource in weblogic and use connection pool.
    In order to make servlet application run significantly faster, my servet how to use connection poo is much moreresonable?
    For example, my servlet has many times database access. Is it true that geting and close a connection whenever
    one time database access finished?
    If from the servlet begins, the db connection is hold till servlet finalize. Will the solution affect the servlet performance? Is there any official document to introduce connection pool program? I search some documents.
    <The Java EE 6Tutorial> introduce some simple intruduction about connection pool.

    1. Use WebLogic Servers Data Source for Database Connections.
    2. Open and close the connections where you need it. Dont open it in begin and close in finalise. That is bad practice.
    3. Even when you invoke Connection.close () webLogic will not close the connection. it will commit the transaction and return it back to the pool rather than physically closing the DB connection.
    4. You can tune data source for minimum, maximum and increments of connections that you need based on your application requirement.

  • How To Use Connection Pooling in Struts.

    Can Somebody have the idea how to use connection pooling. i want to use jakarta commons dbcp, pool.
    using these packages how can i implement the connection pooling for my web application. If Anybody have some idea plz contect me.
    If Somebody have sample code plz send.
    Thks in Advance,

    Read the documentation...?

  • When using tethered capture I often get this notification "The metadata for this photo has been changed by both Lightroom and another application". This slows or stalls the loading of incoming photos. How do I find out which other application is changing

    When using tethered capture I often get this notification "The metadata for this photo has been changed by both Lightroom and another application". This slows or stalls the loading of incoming photos. How do I find out which other application is changing the metadata and stop it?

    Thanks Sean,
    I've had a look at the TC settings dialog and tried to keep it as simple as possible. I also had a copy of LR 4 on the hard drive so have trashed that also incase of any conflicts. LR seems to be running ok now but as said it's an intermittent problem.
    I also have a copy of Capture One on the hard drive so am going to uninstall that also in case it is trying to launch.

  • When i connect to my pc, getting this message-this iphone cannot be used because the apple mobile device service not started.why

    i replaced my apple iphone4,Because that having some technical problems.but when i get new iphone4 that does't have the previous contents that is my contacts,purchased items etc...,but the backup cd is in my hand and also my itunes having the whole content but the device is connecting to my pc,getting this message that is THIS IPHONE  CANNOT BE USED BECAUSE THE APPLE MOBILE DEVICE SERVICE NOT STARTED.
    Please give me a solution
    thank you

    Try the information in this Apple Support Document. http://support.apple.com/kb/ts1567

  • What do they mean by your apple id has been disabled and how do I enable it?  I get this each time I try to update my apps.

    what do they mean by your apple id has been disabled and how do I enable it?  I get this each time I try to update my apps.

    Got it sorted. AN e-mail to teh support centre got me three replies, two reasuring me that someone os working on it and the third giving me the information that the ID is enabled again and ready to use. All within 24h. Of course without any information as to why the problem came up in teh first place. At least it was swift action.

  • HT2292 When I try to connect my iPad, I get this message: iTunes could not connect to this iPad. An unknown error occurred (0xE800000A)

    When I try to connect my iPad, I get this message: iTunes could not connect to this iPad. An unknown error occurred (0xE800000A)

    Let's try the following document with that one:
    iPhone, iPad, iPod touch: Unknown error containing '0xE' when connecting to a Windows PC

  • "Unable to connect to server"  I have wifi connection but I'm getting this error when I try to purchase an app. Why?

    "Unable to connect to server"  I have wifi connection but I'm getting this error when I try to purchase an app. Why? If anyone knows can you please help me thank you in advance. :-(

    Can you load a webpage in Safari with that wifi connection? If so then it's a problem with the iTunes Store app connection. If not then your wifi isn't fully functional and you need to troubleshoot that first.

  • [SQL] how can i get this result....??(accumulation distinct count)

    [SQL] how can i get this result....??(accumulation distinct count)
    Hi everybody,
    pls tell me how can it possible to get result?
    ### sample data
    date visitor
    10-01 A
    10-01 A
    10-01 B
    10-01 B
    10-01 C
    10-01 C
    10-02 A
    10-02 C
    10-02 C
    10-02 D
    10-02 D
    10-03 B
    10-03 B
    10-03 B
    10-03 A
    10-03 A
    10-03 F
    10-04 A
    10-04 A
    10-04 F
    result that i want...like this.
    date date_unqiue_visitors acc_date_unique_visitors
    10-01 3 3
    10-02 3 4
    10-03 3 5
    10-04 2 5
    date distinct visitors : count(distinct visitor)
    but how can i get accumulation distinct visitor count???
    Thanks to every body..

    SQL> select dt,cnt,sum(cnt1) over(order by dt) cnt1
      2  from(
      3  select dt,count(distinct visitor) cnt,sum(flg) cnt1
      4  from
      5   (select dt,visitor,(select decode(count(*),0,1,0)
      6                           from test
      7                           where rowid < t.rowid
      8                           and visitor = t.visitor) flg
      9   from test t)
    10  group by dt);
    DT                CNT       CNT1
    10-01               3          3
    10-02               3          4
    10-03               3          5
    10-04               2          5
    Message was edited by:
            jeneesh
    Wrong...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • HT4847 None of my iOS devises show no or very little storage used. Why am i getting this message. Ron

    I received the iCloud email saying my storage is full.  None of my devises show any or very little storage used.  Why am I getting this type of email?

    your home page to get into your Web site should be index.html (for Mac) or index.htm  (on PC)
    You can name it something other than index, but will be harder to find.  when you create the subjects and link to them, they can can be named anything with the html extension  Or if your using PHP end in .php. There is a Microsoft type asp or aspx but your hosting service has to set up using windows server system.
    My hosting service use a Linux server normally but can convert Windows for a Fee.  UNIX Linux has no concept of asp or aspx.
    See this : https://skitch.com/pjonescet/8mnnx/dreamweaver

  • I fail to get this result ... Take a look at this media..

    Take a look at this media info
    General
    Complete name                            : C:\Users\.......\Downloads\Video\Nightcore --- YouTube.mp4
    Format                                   : MPEG-4
    Format profile                           : Base Media / Version 2
    Codec ID                                 : mp42
    File size                                : 31.1 MiB
    Duration                                 : 3mn 38s
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 1 196 Kbps
    Encoded date                             : UTC 2014-10-19 01:36:36
    Tagged date                              : UTC 2014-10-19 01:36:36
    gsst                                     : 0
    gstd                                     : 218081
    gssd                                     : B4A7DD623MH1413972940055959
    gshh                                     : r3---sn-p5qlsu7l.googlevideo.com
    Video
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : [email protected]
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 1 frame
    Format settings, GOP                     : M=1, N=60
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Duration                                 : 3mn 38s
    Bit rate                                 : 1 002 Kbps
    Maximum bit rate                         : 2 840 Kbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Constant
    Frame rate                               : 30.000 fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.036
    Stream size                              : 26.0 MiB (84%)
    Tagged date                              : UTC 2014-10-19 01:36:38
    Audio
    ID                                       : 2
    Format                                   : AAC
    Format/Info                              : Advanced Audio Codec
    Format profile                           : LC
    Codec ID                                 : 40
    Duration                                 : 3mn 38s
    Bit rate mode                            : Variable
    Bit rate                                 : 192 Kbps
    Maximum bit rate                         : 203 Kbps
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Sampling rate                            : 44.1 KHz
    Compression mode                         : Lossy
    Stream size                              : 4.99 MiB (16%)
    Title                                    : IsoMedia File Produced by Google, 5-11-2011
    Encoded date                             : UTC 2014-10-19 01:36:37
    Tagged date                              : UTC 2014-10-19 01:36:38
    In adobe media encoder cc 2014 there is no GOP option. how can i get this result..???

    Take a look at this media info
    General
    Complete name                            : C:\Users\.......\Downloads\Video\Nightcore --- YouTube.mp4
    Format                                   : MPEG-4
    Format profile                           : Base Media / Version 2
    Codec ID                                 : mp42
    File size                                : 31.1 MiB
    Duration                                 : 3mn 38s
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 1 196 Kbps
    Encoded date                             : UTC 2014-10-19 01:36:36
    Tagged date                              : UTC 2014-10-19 01:36:36
    gsst                                     : 0
    gstd                                     : 218081
    gssd                                     : B4A7DD623MH1413972940055959
    gshh                                     : r3---sn-p5qlsu7l.googlevideo.com
    Video
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : [email protected]
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 1 frame
    Format settings, GOP                     : M=1, N=60
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Duration                                 : 3mn 38s
    Bit rate                                 : 1 002 Kbps
    Maximum bit rate                         : 2 840 Kbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Constant
    Frame rate                               : 30.000 fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.036
    Stream size                              : 26.0 MiB (84%)
    Tagged date                              : UTC 2014-10-19 01:36:38
    Audio
    ID                                       : 2
    Format                                   : AAC
    Format/Info                              : Advanced Audio Codec
    Format profile                           : LC
    Codec ID                                 : 40
    Duration                                 : 3mn 38s
    Bit rate mode                            : Variable
    Bit rate                                 : 192 Kbps
    Maximum bit rate                         : 203 Kbps
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Sampling rate                            : 44.1 KHz
    Compression mode                         : Lossy
    Stream size                              : 4.99 MiB (16%)
    Title                                    : IsoMedia File Produced by Google, 5-11-2011
    Encoded date                             : UTC 2014-10-19 01:36:37
    Tagged date                              : UTC 2014-10-19 01:36:38
    In adobe media encoder cc 2014 there is no GOP option. how can i get this result..???

  • How To Use Connection pooling with j2sdkee1.3?

    hi!
    How to use javax.sql.ConnectionPoolDataSource and
    javax.sql.PooledConnection with j2sdkee1.3.?
    In j2ee1.3's deployment tool,
    to specify the resource factories,
    javax.sql.ConnectionPoolDataSource is not available.
    Please Help me to use Connection pooling.
    Dhaya.

    Vendor implementations usually have a fair amount of optimization. For J2EE apps, my concern would be using your pool in transactional calls. When you make a transactional call across several beans/methods, the vendor's pool makes sure that you get the same connection each time you get a connection from the pool so that if you want to rollback the work (in case an error occurs), you can. Does your current connection pool support this?

Maybe you are looking for

  • How to schedule a load job from bi to r3 daily ? What are the available opt

    I think we can create a PC for the same so should we code an ABAP routine with include to do the process. So can it be scheduled daily, what are the other option in BI7 other than PC ?

  • Loading 8i Personal Edition on MS 98

    When I get the cd's loaded on my computer. How do I access it to use it. Would an Icon appear on my desktop ???? Help!!

  • Random problem opening RAW images from I-photo into Camera Raw 4.1

    Hi there, sometimes when I double click an RAW .NEF image in i-photo it opens into the Camera Raw adjustement window and sometimes not. This is shots from the same shoot and they're all definitely .NEF files. The shots that have already opened always

  • Po line items

    hi friends , i taken internal table for header data  and item data for single table. what code write it in recording for line item and header item.

  • IPhoto "faces" problem

    I am using the latest iPhoto '11, v 9.3.  Just upgraded to Lion.  I had to "upgrade" my library that has worked fine under Snow Leopard.  After the upgrade, a large number of photos (not all) lost Faces identification that was there before.  Further,