Problem with connect  by level

Hi,
My requiremet goes some thing like this : I would like to generate the dates from hiredate to systdate with a gap of one month.The code which I have return works good for single empno . I want to generate the dates from hiredate to sysdate with a gap
of one month for all the employees(empno). commenting the code for where empno = 7369 does not work and the system a lot of CPU usage.
Assume hiredate to be to_date('01-jan-10') for empno = 7369
sample codes goes something like this:
select ADD_MONTHS(trunc(to_date('01-jan-10')),LEVEL-1)
from dual
connect by level <= trunc((sysdate-to_Date('01-jan-10'))/30 )code for emp table
select ADD_MONTHS(trunc(hiredate),LEVEL-1)
from employee
where empno = 7369
connect by level <= trunc((sysdate-trunc(hiredate))/30 )Please advice

Based on emp table, something like this...
SQL> ed
Wrote file afiedt.buf
  1  with emps as (select * from emp where deptno = 10)
  2      ,uppr as (select to_date('31/12/1982','DD/MM/YYYY') as dt from dual)
  3  -- END OF TEST DATA
  4  select empno, ename, add_months(hiredate,rn-1) as dt
  5  from emps, uppr
  6      ,(select rownum rn from dual connect by rownum <= (select max(dt-hiredate) from emps,uppr))
  7  where add_months(hiredate,rn-1) <= uppr.dt
  8* order by empno, rn
SQL> /
     EMPNO ENAME      DT
      7782 CLARK      09/06/1981 00:00:00
      7782 CLARK      09/07/1981 00:00:00
      7782 CLARK      09/08/1981 00:00:00
      7782 CLARK      09/09/1981 00:00:00
      7782 CLARK      09/10/1981 00:00:00
      7782 CLARK      09/11/1981 00:00:00
      7782 CLARK      09/12/1981 00:00:00
      7782 CLARK      09/01/1982 00:00:00
      7782 CLARK      09/02/1982 00:00:00
      7782 CLARK      09/03/1982 00:00:00
      7782 CLARK      09/04/1982 00:00:00
      7782 CLARK      09/05/1982 00:00:00
      7782 CLARK      09/06/1982 00:00:00
      7782 CLARK      09/07/1982 00:00:00
      7782 CLARK      09/08/1982 00:00:00
      7782 CLARK      09/09/1982 00:00:00
      7782 CLARK      09/10/1982 00:00:00
      7782 CLARK      09/11/1982 00:00:00
      7782 CLARK      09/12/1982 00:00:00
      7839 KING       17/11/1981 00:00:00
      7839 KING       17/12/1981 00:00:00
      7839 KING       17/01/1982 00:00:00
      7839 KING       17/02/1982 00:00:00
      7839 KING       17/03/1982 00:00:00
      7839 KING       17/04/1982 00:00:00
      7839 KING       17/05/1982 00:00:00
      7839 KING       17/06/1982 00:00:00
      7839 KING       17/07/1982 00:00:00
      7839 KING       17/08/1982 00:00:00
      7839 KING       17/09/1982 00:00:00
      7839 KING       17/10/1982 00:00:00
      7839 KING       17/11/1982 00:00:00
      7839 KING       17/12/1982 00:00:00
      7934 MILLER     23/01/1982 00:00:00
      7934 MILLER     23/02/1982 00:00:00
      7934 MILLER     23/03/1982 00:00:00
      7934 MILLER     23/04/1982 00:00:00
      7934 MILLER     23/05/1982 00:00:00
      7934 MILLER     23/06/1982 00:00:00
      7934 MILLER     23/07/1982 00:00:00
      7934 MILLER     23/08/1982 00:00:00
      7934 MILLER     23/09/1982 00:00:00
      7934 MILLER     23/10/1982 00:00:00
      7934 MILLER     23/11/1982 00:00:00
      7934 MILLER     23/12/1982 00:00:00
45 rows selected.
SQL>(I limited the upper date to 31/12/1982 rather than sysdate as I didn't want too much data... :D)

Similar Messages

  • Performance issue with connect by level query

    Hi I have a problem with connect by level in oracle.
    My table is :
    J_USER_CALENDAR
    USER_NAME     FROM_DATE     TO_DATE     COMMENTS
    Uma Shankar     2-Nov-09     5-Nov-09     Comment1
    Veera     11-Nov-09     13-Nov-09     Comment2
    Uma Shankar     15-Dec-09     17-Dec-09     Commnet3
    Vinod     20-Oct-09     21-Oct-09     Comments4
    The above table is the user leave calendar.
    Now I need to display the users who are on leave between 01-Nov-2009 to 30-Nov-2009
    The output should look like:
    USER_NAME     FROM_DATE     COMMENTS
    Uma Shankar     2-Nov-09     Comment1
    Uma Shankar     3-Nov-09     Comment1
    Uma Shankar     4-Nov-09     Comment1
    Uma Shankar     5-Nov-09     Comment1
    Veera     11-Nov-09     Comment2
    Veera     12-Nov-09     Comment2
    Veera     13-Nov-09     Comment2
    For this I have tried with following query , but it is taking too long time to execute.
    select FROM_DATE,user_name,comments from (SELECT distinct FROM_DATE,user_name ,
    comments FROM (SELECT (LEVEL) + FROM_DATE-1 FROM_DATE,TO_DATE, FIRST_NAME||' '|| LAST_NAME
    user_name ,COMMENTS FROM J_USER_CALENDAR
    where
    and J_USER_CALENDAR.IS_DELETED=0
    CONNECT BY LEVEL <= TO_DATE - FROM_DATE+1) a )where (FROM_DATE = '01-Nov-2009' or FROM_DATE = '30-Nov-2009'
    or FROM_DATE between '01-Nov-2009' and '30-Nov-2009') order by from_Date ,lower(user_name)
    Please help me.
    Thanks in advance.
    Regards,
    Phanikanth

    I have not attempted to analyze your SQL statement.
    Here is a test set up:
    CREATE TABLE T1(
      USERNAME VARCHAR2(30),
      FROM_DATE DATE,
      TO_DATE DATE,
      COMMENTS VARCHAR2(100));
    INSERT INTO T1 VALUES ('Uma Shankar', '02-Nov-09','05-Nov-09','Comment1');
    INSERT INTO T1 VALUES ('Veera','11-Nov-09','13-Nov-09','Comment2');
    INSERT INTO T1 VALUES ('Uma Shankar','15-Dec-09','17-Dec-09','Commnet3');
    INSERT INTO T1 VALUES ('Vinod','20-Oct-09','21-Oct-09','Comments4');
    INSERT INTO T1 VALUES ('Mo','20-Oct-09','05-NOV-09','Comments4');
    COMMIT;Note that I included one additional row, where the person starts their vacation in the previous month and ends in the month of November.
    You could approach the problem like this:
    Assume that you would like to list all of the days of a particular month:
    SELECT
      TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY
    FROM
      DUAL
    CONNECT BY
      LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY');Note that the above attempts to calculate the number of days in the month of November - if it is known that the month has a particular number of days, 30 for instance, you could rewrite the CONNECT BY clause like this:
    CONNECT BY
      LEVEL<=30Now, we need to pick up those rows of interest from the table:
    SELECT
    FROM
      T1 T
    WHERE
      (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')
        OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY'));
    USERNAME        FROM_DATE TO_DATE   COMMENTS
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1
    Veera           11-NOV-09 13-NOV-09 Comment2
    Mo              20-OCT-09 05-NOV-09 Comments4If we then join the two resultsets, we have the following query:
    SELECT
    FROM
      T1 T,
      (SELECT
        TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY
      FROM
        DUAL
      CONNECT BY
        LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY')) V
    WHERE
      (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')
        OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY'))
      AND V.MONTH_DAY BETWEEN T.FROM_DATE AND T.TO_DATE
    ORDER BY
      USERNAME,
      MONTH_DAY;
    USERNAME        FROM_DATE TO_DATE   COMMENTS   MONTH_DAY
    Mo              20-OCT-09 05-NOV-09 Comments4  01-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  02-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  03-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  04-NOV-09
    Mo              20-OCT-09 05-NOV-09 Comments4  05-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   02-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   03-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   04-NOV-09
    Uma Shankar     02-NOV-09 05-NOV-09 Comment1   05-NOV-09
    Veera           11-NOV-09 13-NOV-09 Comment2   11-NOV-09
    Veera           11-NOV-09 13-NOV-09 Comment2   12-NOV-09
    Veera           11-NOV-09 13-NOV-09 Comment2   13-NOV-09Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Hi Guys, I have a problem with Rosemount Radar Level Trasnmitter Model 5400 series with Foundation Fieldbus

    Hi Guys, I have a problem with Rosemount Radar Level Trasnmitter Model 5400 series with Foundation Fieldbus, the indication of radar in NI-FBUS software configurator was good no Error, but when I try to connect the segment to the Centum VP DCS, the radar lost in the list, but another device in the segment still in the list, only the radar lost from the list.please your advice what make the radar lost in the list?, Thank you
    Attachments:
    Radar Level Tranmitter 5400FF.pdf ‏516 KB

    Hi Nanda,
    Would you check if the addresses of the device conflicts with one of the new devices in the cascaded segments?
    If this is not the issue, can you try to see what happens if you only use this one device with the same procedure you have done? Just wanna try to narrow down where the problem is. A capture by FBUS Monitor is even better.
    Thanks.

  • Problem with connecting and syncing   (quicktime.qts)

    Hi,
    I have a problem with connecting and syncing my Iphone to itunes.
    iphone alone on PC -> uploading files (fotos) is possible
    itunes starts normaly, if iphone is not conected.
    if i connect iphone after starting itunes, or if i start itunes after connecting iphone i get an itunes-error with message:
    AppName: itunes.exe AppVer: 9.0.2.25 ModName: quicktime.qts
    ModVer: 7.65.17.80 Offset: 00909a47
    i test different things...
    - used another USB-port
    - used another PC
    - used macbook of my wife instead PC
    - deinstalled and new installed of itunes (older and newer versions) folow tutorials of apple
    - use another USB-Cable...
    I'm resigned, Please help me..
    Tom

    AppName: itunes.exe AppVer: 9.0.2.25 ModName: quicktime.qts
    In this context, that can sometimes indicate trouble with a content file on the phone (or Touch).
    Do you have any podcasts stored on the iPhone at the moment? If so, if you delete them from the phone, can you connect to iTunes without the error?

  • HT204053 I have a problem. I bought Pages and Numbers for my iMac and so far everything was OK.  Suddenly i have a problem with connection to iCloud. Dokuments created on iMac in Pages or Numbers are not transfered to iCloud. Not uploaded in iCloud.

    I have a problem.
    I bought Pages and Numbers for my iMac and so far everything was OK.
    Suddenly i have a problem with connection to iCloud.
    Dokuments created on iMac in Pages or Numbers are not transfered to iCloud. Not uploaded to iCloud. There is a sign  (small shape of iCloud), that they are waiting to be uploaded to iCloud.
    I think the iCloud is OK.
    i can see and manage documents in iCloud. i can create them on iPad and  see them and delete them in iCloud.
    But not on iMac.
    i dont know what has happened and I am not abble to find the solution. It was OK till some days ago….

    I have a similar problem! Everything stopped working after upgrading to Mac OS 10.8.4 through the App Store. Help!

  • Problem with connecting to free wifi after upgrading to Windows 8.1 from Windows 8

    Hi
    I had problems with connecting to free Wifi after upgrading my PC(Notebook) to Windows 8.1 from Windows 8. As I travel a lot within europe, I am used to being able to connect to Free Wifi(those that dont need a key or password to enter) but soon after downloading
    Windows 8.1 I almost never was able to do this. I'd always get «LIMITED» even though the signal was strong.This was so fustrating,so much so that I reset my PC to clear it of Windows 8.1 and am now back to Windows 8.This is a shame because I was really liking
    using Windows 8.1 and if not for this problem(which is a big one) I'd still be using it. If I download Windows 8.1 again from the Windows store what is the probability that I'll have the same problems?
    Thanks Portozzygirl

    More often than not when a device isn't working it is because the driver has become corrupted. Re-installing a fresh copy should help
    http://windows.microsoft.com/en-us/windows7/Update-a-driver-for-hardware-that-isnt-working-properly?SignedIn=1
    http://captaindbg.com/how-to-update-drivers-on-windows-7/   (works on win 8 too)
    Wanikiya and Dyami--Team Zigzag

  • After I've upgraded my iPhone iOS to 5.0.1, I got problems with connectivity. If my iPhone lose network, then it gets frozzen and I cannot make calls. After restart the telephone still does not work.

    After I've upgraded my iPhone iOS to 5.0.1, I got problems with connectivity. If my iPhone lose network, then it gets frozzen and I cannot make calls. After restart the telephone still does not work.

    1. Download the iOS 5.0.1: http://www.tobias-hartmann.net/2011/11/download-ios-5-0-1-veroffentlicht-direkte -downloadlinks/
    2. open itunes,Click in iTunes while holding down the Shift key (on Windows) or Alt key (Mac) to restore and firmware

  • How do I get connected to a server on my network via an IP address?  When I try to open in a URL and login as a registered user with proper login it errors out saying there was a problem with connecting to the server?

    I am new to Mac...How do I get connected to a server on my network via a hyper link IP address path?  When I try to open in a URL and login as a registered user with proper login it errors out saying there was a problem with connecting to the server?

    Some of the following is going to use some technical terms — this area is inherently somewhat technical. 
    If you don't understand some part of the following reply, please ask.
    Is this your own OS X Server system on your own network, or is this some other server within some larger organization? 
    You're posting this in the OS X Server forum, which is a software package that allows OS X systems to provide web-based and many other services; to become servers.
    If it's your OS X Server on your network, then the network and DNS configurations are suspect, or the server is somehow malfunctioning or misconfigured.   This is unfortunately fairly common, as some folks do try to avoid setting up DNS services.
    If it's a larger organization and somebody else is managing the server and the network, then you'll probably need to contact the IT folks for assistance; to learn the network setup and DNS requirements, and if there's a problem with the server itself.
    The basic web URL "hyper link IP address path" — without using DNS — usually looks something the following, where you'll need to replace 10.20.30.40 with the IP address of your server:
    http://10.20.30.40
    UptimeJeff has posted a URL that specifies the AFP file system; an OS X file share.  That's used if you're connecting to an Apple storage service somewhere on your network.  You might alternatively need to specify smb://10.20.30.40 or such, if it's a Windows file server.  (There can be additional requirements for connecting to Windows Server systems, too.)
    If there's local IT staff available here, please contact them for assistance.  If these are your own local systems and your own local OS X Server system, then some information on the server will be needed.  (If you're on a NAT'd network, you'll also need to get DNS services configured and working on your local OS X Server system and your network — you'll not be able to skip this step and reference ISP DNS servers here — or things can and usually will get weird.)

  • Problem with setting Source Level in Sun Studio 2

    I've got problem with setting Source Level to 1.5 in Sun Studio 2. When I try to set it to 1.5 in Project properties and click Ok everything seem to go well, but when I open Project Properties again Source Level is set to 1.4. I need this to work cause I started to lear Java recently and I want to use foreach loop.
    Please help

    I'm just citing an example using Date().
    In fact, whether I use DateFormat or Calendar, it shows the same result.
    When I set the date to 1 Jan 1950 0 hours 0 minutes 0 seconds,
    jdk1.4.2 will always return me 1 Jan 1950 0 hours 10 minutes 0 seconds.
    It works correctly under jdk1.3.1

  • Problem with connecting to DB2 from ADFBC

    I have a problem with connection to DB2 data using ADF BC components. Everything looks fine till I run the page(JSF) to see the data of a db2 table. I created a read only view object. This view is registered in the AM and from AM the view is returning the rows without any problem. But when I am running the page which has the view as a table these errors are thrown. Please help me to fix this.
    JBO-30003: The application pool (od.mft.views.MFTServiceLocal) failed to checkout an application module due to the following exception:
    oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=JBO-29000: Unexpected exception caught: oracle.jbo.DMLException, msg=JBO-26061: Error while opening JDBC connection.
    at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2002)
    ## Detail 0 ##
    oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=JBO-29000: Unexpected exception caught: oracle.jbo.DMLException, msg=JBO-26061: Error while opening JDBC connection.
    at oracle.jbo.pool.ResourcePool.useResource(ResourcePool.java:336)
    ## Detail 0 ##
    oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.DMLException, msg=JBO-26061: Error while opening JDBC connection.
    at oracle.jbo.pool.ResourcePool.createResource(ResourcePool.java:545)
    ## Detail 0 ##
    oracle.jbo.DMLException: JBO-26061: Error while opening JDBC connection.
    at oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:220
    ## Detail 0 ##
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager.java:545)
    Thanks
    Gangs

    Steve, the tester works good as expected and its retreiving the rows. As I said earlier the problem is with the JSF page when I ran the page on Embeded Oc4j of Jdev the page showing the above. The exception does not show on the console.
    Please let me know if you need any more details.
    thanks
    Gangs

  • Problem with connecting ipad 2 with crestron cp2e...help plss its urgent... I hv a ipad 2 with mobile pro g connected with cp2e. when i pressed any button in ipad its connet with cp2e but after 4-5 sec one error comes (warning wifi was powered off while t

    problem with connecting ipad 2 with crestron cp2e...help plss its urgent...
    I hv a ipad 2 with mobile pro g connected with cp2e. when i pressed any button in ipad its connet with cp2e but after 4-5 sec one error comes (warning wifi was powered off while the device was in auto -lock(sleep)press connect to reconnect) when i pressed again its connected with cp2e. i am using netgear wireless access point . i also has been changed access point as well as updated ipad firmware bt problem is as it is .. pls help.

    Hi have you solved the issue ?
    Cause I have the same problem.
    Tnx

  • Experiencing problems with connecting my iPhone 6plus to my Hyundai sonata phone kit via Bluetooth, Experiencing problems with connecting my iPhone 6plus to my Hyundai sonata phone kit via Bluetooth

    Experiencing problems with connecting my iPhone 6plus to my Hyundai sonata phone kit via Bluetooth, Experiencing problems with connecting my iPhone 6plus to my Hyundai sonata phone kit via Bluetooth

    Hello NiiTeye,
    I'm sorry to hear you are having these issues with your iPhone. If you are having issues connecting to your car stereo via Bluetooth, you may find the troubleshooting steps outlined in the following articles helpful:
    Get help using your iPhone, iPad, or iPod touch with your car stereo - Apple Support
    iOS: Troubleshooting Bluetooth connections - Apple Support
    Sincerely,
    - Brenden

  • Problems with connection to the Mountain Lion

    Someone is having problems with connection on Mac Mountain Lion? I did a clean install and the connection is unstable.

    Have you tried to reset your network settings ?
    What I would do is delete the connection, and then retry the set up of that connection.
    System Preferences>Network, select Wi-Fi on the left and then click on the 'minus' button

  • I am having problems with connecting to my router wireles...

    I am having problems with connecting to my router wirelessly.  How do I determine my access point's network key?

    Follow this from a computer already connected: 1. Open setup page of router by typing http://192.168.1.1 in browser’s address bar, and typing password as "admin" and no user name. Use your password if you have changed it earlier. 2. Go to wireless tab. 3. Go to wireless security sub-tab. 4. If security mode is wpa or wpa2 note down pass phrase/shared key, if security mode is WEP note down wep key number 1. This will be your network key.

  • Contribute 3: Problem with Connection Key

    Hi,
    I'm having a problem with connecting Contribute 3 to our web
    site.
    I have Contribute running on two PC's, one running XP Pro
    Service Pack 1 and the other Service Pack 2, the one with SP 1 is
    at home and connects fine. I used this one to generate a connection
    key for my office computer (the one with SP2). Everything should be
    fine, but it isn't.
    The office PC refused to connect to the site: After double
    clicking on the connection key and selecting Open, it presents a
    dialog box with the name: Import Connection Key, and I enter a new
    username, email and the password for the connection key.
    When I click OK, it presents the following message: "Unknown
    host. Contribute could not find the server "ftp.myhost.com". Please
    check your connection information or contact your administrator."
    When I click OK on this dialog box, it presents the following
    dialog box: "Contribute could not verify your connection key. A
    network connection to the server could not be established. Please
    contact your administrator for assistance." Damn,I'm the
    adminstrator and I have run out of ideas!
    I can connect to the site with WS_FTP without any problems,
    but I cannot do so with Contribute, neither with the connection key
    containing all the FTP details, nor bypassing the connection key
    and simply manually entering the FTP details.
    What is going on

    which windows version do you have? 
    connect your phone to your PC > disable your firewall and antivirus > your PC should download the drivers also you might want to try SUS 
    Update Service (SUS)
    PC Companion (PCC)
    Bridge (for Mac)
    Alternatives on How to backup Xperias
    http://talk.sonymobile.com/thread/36355
    "I'd rather be hated for who I am, than loved for who I am not." Kurt Cobain (1967-1994)

Maybe you are looking for