When CONNECT_BY_ISLEAF can't do the job?

Hi everyone,
I have an issue with CONNECT_BY_ISLEAF. I would like to add conditions on it. Can anyone help? I'm using Oracle 10g.
Let's take the following scenario:
DROP TABLE departments;
CREATE TABLE departments
  dpt_id NUMBER(10) UNIQUE,
  dpt_name VARCHAR2(100),
  dpt_parent_id NUMBER(10),
  is_valid NUMBER(1)
INSERT INTO departments VALUES(1, 'Company', null, 1);
INSERT INTO departments VALUES(2, 'HR', 1, 1);
INSERT INTO departments VALUES(3, 'SALES', 1, 1);
INSERT INTO departments VALUES(4, 'IT', 1, 1);
INSERT INTO departments VALUES(222, 'Helpdesk', 4, 1);
INSERT INTO departments VALUES(223, 'French Speaking', 222, 1);
INSERT INTO departments VALUES(224, 'Another level', 223, 0);
INSERT INTO departments VALUES(5, 'LEGAL', 1, 1);
INSERT INTO departments VALUES(66, 'Recruitment', 2, 1);
INSERT INTO departments VALUES(33, 'Logistics', 2, 1);
INSERT INTO departments VALUES(39, 'Fleet management', 33, 1);
INSERT INTO departments VALUES(31, 'Local Sales', 3, 1);
INSERT INTO departments VALUES(60, 'European Sales', 3, 1);
INSERT INTO departments VALUES(61, 'Germany', 60, 1);
INSERT INTO departments VALUES(62, 'France', 60, 1);
INSERT INTO departments VALUES(620, 'Paris', 62, 1);
INSERT INTO departments VALUES(621, 'Marseilles', 62, 1);
INSERT INTO departments VALUES(38, 'American Sales', 3, 1);
INSERT INTO departments VALUES(34, 'Asian Sales', 3, 1);
INSERT INTO departments VALUES(9999, 'VIP 01', 1, 1);
INSERT INTO departments VALUES(9998, 'Politicians', 9999, 1);
INSERT INTO departments VALUES(9997, 'Singers', 9999, 1);
INSERT INTO departments VALUES(9996, 'Korean Singers', 9997, 1);
INSERT INTO departments VALUES(6325, 'VIP 02', 1, 1);
INSERT INTO departments VALUES(6311, 'Steering Bord', 6325, 0);
INSERT INTO departments VALUES(6310, 'Another high level group', 6325, 0);
COMMIT;I have a departments table that is recursive. The link to a parent department is done through dpt_parent_id and root nodes have a null value in this attribute.
As you can see, I also have a flag identifying what node is valid or not. Invalid nodes should not be taken into considerations in the CONNECT_BY_ISLEAF operator. Can this be achieved?
The following statement:
SELECT dpt_id, dpt_name, is_valid, CONNECT_BY_ISLEAF, LPAD(' ', (LEVEL-1) * 2) || dpt_name as indented_name
   FROM departments
  START WITH dpt_parent_id IS NULL
CONNECT BY PRIOR dpt_id = dpt_parent_id;returns this result:
1     Company                    1     0     Company
2     HR                         1     0       HR
33     Logistics                    1     0         Logistics
39     Fleet management          1     1           Fleet management
66     Recruitment               1     1         Recruitment
3     SALES                    1     0       SALES
31     Local Sales                    1     1         Local Sales
34     Asian Sales                    1     1         Asian Sales
38     American Sales               1     1         American Sales
60     European Sales               1     0         European Sales
61     Germany                    1     1           Germany
62     France                    1     0           France
620     Paris                         1     1             Paris
621     Marseilles                    1     1             Marseilles
4     IT                         1     0       IT
222     Helpdesk                    1     0         Helpdesk
223     French Speaking               1     0           French Speaking
224     Another level               0     1             Another level               -- incorrect
5     LEGAL                    1     1       LEGAL
6325     VIP 02                    1     0       VIP 02
6310     Another high level group     0     1         Another high level group    -- incorrect
6311     Steering Bord               0     1         Steering Bord                   -- incorrect 
9999     VIP 01                    1     0       VIP 01
9997     Singers                    1     0         Singers
9996     Korean Singers               1     1           Korean Singers
9998     Politicians                    1     1         PoliticiansThe previous result is wrong. The three records marked incorrect don't have the right result. Because their parent nodes only have invalid children, they should be the leaf... So, instead, I should have something like:
1     Company                    1     0     Company
2     HR                         1     0       HR
33     Logistics                    1     0         Logistics
39     Fleet management          1     1           Fleet management
66     Recruitment               1     1         Recruitment
3     SALES                    1     0       SALES
31     Local Sales                    1     1         Local Sales
34     Asian Sales                    1     1         Asian Sales
38     American Sales               1     1         American Sales
60     European Sales               1     0         European Sales
61     Germany                    1     1           Germany
62     France                    1     0           France
620     Paris                         1     1             Paris
621     Marseilles                    1     1             Marseilles
4     IT                         1     0       IT
222     Helpdesk                    1     0         Helpdesk
223     French Speaking               1     1           French Speaking                -- correct now
224     Another level               0     0             Another level
5     LEGAL                    1     1       LEGAL
6325     VIP 02                    1     1       VIP 02                                 -- correct now !!
6310     Another high level group     0     0         Another high level group
6311     Steering Bord               0     0         Steering Bord              
9999     VIP 01                    1     0       VIP 01
9997     Singers                    1     0         Singers
9996     Korean Singers               1     1           Korean Singers
9998     Politicians                    1     1         Politicians The two nodes marked correct are "the leaves" even if technically they are not. They only have invalid children, so they should be the leaves.
Is there any chance I can tweak the CONNECT_BY_ISLEAF operator to take into consideration this invalid status?
Thanks

Not exactly sure what you are trying to do, but it looks like this:
SELECT  dpt_id, dpt_name,
        is_valid,
        is_valid * CONNECT_BY_ISLEAF CONNECT_BY_ISLEAF,
        LPAD(' ', (LEVEL-1) * 2) || dpt_name as indented_name
  FROM  departments
  START WITH dpt_parent_id IS NULL
  CONNECT BY PRIOR dpt_id = dpt_parent_id;
    DPT_ID DPT_NAME                         IS_VALID CONNECT_BY_ISLEAF INDENTED_NAME
         1 Company                                 1                 0 Company
         2 HR                                      1                 0   HR
        33 Logistics                               1                 0     Logistics
        39 Fleet management                        1                 1       Fleet management
        66 Recruitment                             1                 1     Recruitment
         3 SALES                                   1                 0   SALES
        31 Local Sales                             1                 1     Local Sales
        34 Asian Sales                             1                 1     Asian Sales
        38 American Sales                          1                 1     American Sales
        60 European Sales                          1                 0     European Sales
        61 Germany                                 1                 1       Germany
    DPT_ID DPT_NAME                         IS_VALID CONNECT_BY_ISLEAF INDENTED_NAME
        62 France                                  1                 0       France
       620 Paris                                   1                 1         Paris
       621 Marseilles                              1                 1         Marseilles
         4 IT                                      1                 0   IT
       222 Helpdesk                                1                 0     Helpdesk
       223 French Speaking                         1                 0       French Speaking
       224 Another level                           0                 0         Another level
         5 LEGAL                                   1                 1   LEGAL
      6325 VIP 02                                  1                 0   VIP 02
      6310 Another high level group                0                 0     Another high level group
      6311 Steering Bord                           0                 0     Steering Bord
    DPT_ID DPT_NAME                         IS_VALID CONNECT_BY_ISLEAF INDENTED_NAME
      9999 VIP 01                                  1                 0   VIP 01
      9997 Singers                                 1                 0     Singers
      9996 Korean Singers                          1                 1       Korean Singers
      9998 Politicians                             1                 1     Politicians
26 rows selected.
SQL> SY.

Similar Messages

  • How to stop iTunes creating a new library on my hard drive when it can't find the one I have created and told it to use on an external drive?

    I have quite alot of music etc so to save hard drive space I have created my iTunes library on an external hard drive. If I ever accidentaly open iTunes when that external hard drive isn't attached iTunes makes a whole new library from scratch on my computers hard drive. I find this highly frustrating as I often open Itunes to find no music as it have changed librarys and I have to re-load my actual library: very frustraiting and time consuming.
    I would like to know if it is possible to lock iTunes some how to stop it from changing folders when it can'f find the library, or atleast give me a warning that it can't find the library before creating a whole new one????

    Tunes works through a database file which has a list of your tracks.  When you click on a track it looks up in the database which file it needs to play, then plays the file.  If something breaks this link then you get !  The two main ways to get ! are to move a file from where iTunes expects it to be, or to delete it altogether.  I don't know which has happened in your case.  You can try using Spotlight to find a file for the one referred to in a broken link.  If the files have been moved then they need to be moved back.  If they were deleted completely you will have to restore them from a backup or download them again from the iTunes Store and rebuild your library.

  • Is there a way to delete an app when you can't see the app's icon?

    Is there a way to delete an app when you can't see the app's icon? I have so many apps that they don't all show up on the existing screens. I know it can be done by connecting to a computer and using iTunes, but I'm on the road away from my Mac.

    I tried that and instead of showing me the inaccessible screens, it just shortens the number of available screens. Then if I reset the home screen in preferences it removes the folders I created and I'm back to square one.

  • What do you do when you can't read the code on a iTunes gift card?

    What do you do when you can't read the code on a iTunes gift card? I tried taking it back to the store with my reciept, but they said I would have to contact Apple support. Am I out just out $25 dollars?

    See this support article:
    http://support.apple.com/kb/TS1292
    Instructions are at the bottom of that article.
    BTW, this forum is for questions about iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. Normally you want to ask your questions in the general iTunes forums.
    Regards.

  • How to decrypt data when you can't get the private key in Windows?

    I'm very confuse. My english is poor, but I try to say my question clearly.
    When browser connects to a https website which needs client certificate to authenticate the identity, the browser will send client certificate to web server.
    Then the web server will use the certificate to encrypt some data and send it to browser.
    Then broswer should have private key to decrypt that.
    But as I know, if I install a pfx format personal certificate, I can set can't export private key, which means you can't get the private key to use it. So how can
    the browser decrypt the data without private key?
    By the way, what is CSP, use CSP's interface can we use CryptoAPI
    to decrypt data without private key?

    Answer for question is  "you cant".. 
    "How to decrypt data when you can't get the private key in Windows?"
    Read more 
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa387460(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/library/windows/desktop/bb427432(v=vs.85).aspx
    http://technet.microsoft.com/en-us/library/dd277320.aspx
    http://en.wikipedia.org/wiki/Public-key_cryptography

  • Hi i have 50 infoobjects as part of my aggregates and in that 10 infoobjects have received changes in masterdata.so in my process chain the Attribute change run in running for a long time.can i kill the job and repeat the same.

    Hi i have 50 infoobjects as part of my aggregates and in that 10 infoobjects have received changes in masterdata.so in my process chain the Attribute change run in running for a long time.can i kill the job and repeat the same.

    Hi,
    I believe this would be your Prod system, so don't just cancel it but look at the job log. If it is still processing then don't kill it and wait for the change run to complete but if you can see that nothing is happening and it is stuck for a long time then you can go ahead and cancel it.
    But please be sure, as these kind of jobs can create problems if you cancel them in the middle of a job.
    Regards,
    Arminder Singh

  • How can I suspend the job using IPP_CANCEL_JOB of ipp api

    hi, Can anyone help how can I suspend the job using IPPCANCELJOB of ipp api,so that I can cancel my previous job.
    thanks

    As before, you should try http://lists.apple.com/mailman/listinfo/printing.

  • Can a execute the job in parallel.?

    Please find below my DBMS_SHEDULER job:
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB
    (job_name => 'job1',
    job_type => 'PLSQL_BLOCK',
    job_action => 'BEGIN pk_dt_auto.pr_fire_process(''764''); END;'
    start_date => SYSDATE,
    repeat_interval =>'FREQ = Minutely; INTERVAL = 'SYSDATE+ 30/86400'
    END;
    Can i run the job twice in parallel?..

    Hi,
    For dbms_scheduler (and dbms_job) once a job is running it will NOT be started again until after it has finished. The scheduler ensures that only one instance of a job is running at a given time.
    There is a way around this however. In your job, instead of doing the manipulations, create a simple one-time job with a unique name (dbms_scheduler.generate_job_name) that does the manipulations. Since creating a job is fairly quick the main job will finish quickly and be rescheduled for after the interval but the one-time job will continue doing the work in the background .
    Hope this helps,
    Ravi.

  • What do I do when I can not find the curser

    what do I do when I can not find the curser

    The esc key will hide the cursor, hitting the esc key again will reveal it.
    So try hitting the esc key and then move the mouse (or swipe the track pad). If there is no cursor visible anywhere, do the same thing again.

  • How do you remove an apple id when you can not contact the previous user?

    I am working with a local Pawn shop that purchased an ipad from an indavidual. They restored the ipad and apparently, the contact info from the user is bogus. So, is there any way to get the apple id removed when you can not contact the previous owner? I have the serial number and any other info that may be needed.

    No, there is no way to remove the previous user ID. If the previous owners information was bogus the iPad is likely stolen.

  • HT201441 how can i activate my phone when i can't remember the apple ID that was logged inside my iphone?

    how can i activate my phone when i can't remember the apple ID that was logged inside my iphone?

    To find your Apple IDs go here...
    Look up your old and forgotten Apple ID

  • Why does my ITunes now get stuck when it can't find the album art?

    I've noticed since yesterday when I bought my new IPod Touch my ITunes on my computer gets stuck when it can't find the album art for some music I have. It gets to that album and won't do anything, won't let me skip it or anything ... Anyone else having similar issues and if so any workaround?

    Hi joanhello,
    I understand that you are seeing an issue with iTunes fetching information about CDs you are importing. Here is an article for you that explains how to troubleshoot this issue:
    iTunes 11 for Windows: If you don’t see song information
    http://support.apple.com/kb/PH12488
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • How do you unlock your itunes account when you can't remember the answers to your security questions?

    How do you unlock your itunes account when you can't remember the answers to your security questions?

    Click here for information. If you can't get the answers emailed to you for some reason, contact the iTunes Store staff via the link in that article.
    (75741)

  • HT1212 I've forgotten my ipad passcode but when I try to restore on the computer it won't let me as I have to turn "find your ipad" off but i don't know how when I can't use the  ipad itself. How do I do this on the cloud?

    I've forgotten my ipad passcode but when I try to restore on the computer it won't let me as I have to turn "find your ipad" off but i don't know how when I can't use the  ipad itself. How do I do this on the cloud?

    If the iPad was running iOS 7,  iCloud: Find My iPhone Activation Lock in iOS 7
    http://support.apple.com/kb/HT5818
    How can I unlock my iPad if I forgot the passcode?
    http://www.everymac.com/systems/apple/ipad/ipad-troubleshooting-repair-faq/ipad- how-to-unlock-open-forgot-code-passcode-password-login.html
    iOS: Device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    How can I unlock my iPad if I forgot the passcode?
    http://tinyurl.com/7ndy8tb
    How to Reset a Forgotten Password for an iOS Device
    http://www.wikihow.com/Reset-a-Forgotten-Password-for-an-iOS-Device
    Using iPhone/iPad Recovery Mode
    http://ipod.about.com/od/iphonetroubleshooting/a/Iphone-Recovery-Mode.htm
    Saw this solution on another post about an iPad in a school environment. Might work on your iPad so you won't lose everything.
    ~~~~~~~~~~~~~
    ‘iPad is disabled’ fix without resetting using iTunes
    Today I met my match with an iPad that had a passcode entered too many times, resulting in it displaying the message ‘iPad is disabled – Connect to iTunes’. This was a student iPad and since they use Notability for most of their work there was a chance that her files were not all backed up to the cloud. I really wanted to just re-activate the iPad instead of totally resetting it back to our default image.
    I reached out to my PLN on Twitter and had some help from a few people through retweets and a couple of clarification tweets. I love that so many are willing to help out so quickly. Through this I also learned that I look like Lt. Riker from Star Trek (thanks @FillineMachine).
    Through some trial and error (and a little sheer luck), I was able to reactivate the iPad without loosing any data. Note, this will only work on the computer it last synced with. Here’s how:
    1. Configurator is useless in reactivating a locked iPad. You will only be able to completely reformat the iPad using Configurator. If that’s ok with you, go for it – otherwise don’t waste your time trying to figure it out.
    2. Open iTunes with the iPad disconnected.
    3. Connect the iPad to the computer and wait for it to show up in the devices section in iTunes.
    4. Click on the iPad name when it appears and you will be given the option to restore a backup or setup as a new iPad (since it is locked).
    5. Click ‘Setup as new iPad’ and then click restore.
    6. The iPad will start backing up before it does the full restore and sync. CANCEL THE BACKUP IMMEDIATELY. You do this by clicking the small x in the status window in iTunes.
    7. When the backup cancels, it immediately starts syncing – cancel this as well using the same small x in the iTunes status window.
    8. The first stage in the restore process unlocks the iPad, you are basically just cancelling out the restore process as soon as it reactivates the iPad.
    If done correctly, you will experience no data loss and the result will be a reactivated iPad. I have now tried this with about 5 iPads that were locked identically by students and each time it worked like a charm.
    ~~~~~~~~~~~~~
    Try it and good luck. You have nothing more to lose if it doesn't work for you.
     Cheers, Tom

  • How can we change the Job priority in the Source system

    Hi All,
    We are facing an issue with the process chain execution in the Production system. We have a process chain which runs daily in BI system and the chain is designed in such a way, that as soon as the chain starts in BI system,  a corresponding job is triggered in the Source system (ECC  6.0system).
    Now the issue is that after we have our Source system upgraded the memory allocation for the particular Job (FIGL )is reduced and due to which the FIGL job is failing frequently. When we have consulted some experts.They  advised Us to increase the Priority of the Job in source system to A/1, as of now the job is running in B/2 priority.
    Please let us know the way how we can increase the priority of the Source system Job, so that when the process chain triggers a job in source system and that particular jobs  should run with Priority A/1.
    Thanks in advance.
    Regards,
    Chandra.

    Hi Chandra,
    First please find the job name in SM37 for FIGL and check the job status to be in "released" status. Select that job and go to job menu and click on change. then it will take you to the job screen where you have "job class". Here you can change the job class to "A" to get to high priority.
    If you are unable to edit the job then create a new job with the same variants by clicking STEP button in the Job screen.
    Try these steps, let me know if are able to do so.
    Regards,
    Ravi Kanth

Maybe you are looking for