Connect By skipping some ancestors

If I have a hierarchy set up in a table like the following:
id parentID permission
1 null y
2 1 n
3 2 y
4 3 n
5 4 y
using a connect by statement I could get the tree structure like 1->2->3->4->5. My question is, what if due to permissions (or some criteria), someone should only be able to get certain rows, but i still want them in their tree structure linked to the nearest ancestor they have permissions to. So the structure for the sample table i put up top should be 1->3->5. This is because 1 is the nearest ancestor of 3 that has permission = 'y', so 3 is linked under 1. Same for 5, its nearest ancestor with permission = 'y' is 3, so they get linked. This is just a simple example, because obviously each node could have more than one child. Does anyone know how i could do this all with one statement?

First one seems to work OK, not sure about second, I got 97 rows when I tried it against EMP table - perhaps I made a mistake (are all the joins to t necessary?)
Figured you might do this using SYS_CONNECT_BY_PATH in place of subquery. Below is a 'yours vs. mine', which I found did about 5% of the Logical IO (which was nice).
Personal Oracle Database 10g Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> SELECT empno, ename, privs
  2  FROM   emp;
     EMPNO ENAME      P
      7369 SMITH      Y
      7499 ALLEN      Y
      7521 WARD       Y
      7566 JONES      N
      7654 MARTIN     Y
      7698 BLAKE      Y
      7782 CLARK      Y
      7788 SCOTT      Y
      7839 KING       Y
      7844 TURNER     Y
      7876 ADAMS      Y
      7900 JAMES      Y
      7902 FORD       Y
      7934 MILLER     Y
14 rows selected.
SQL> SET AUTOTRACE ON STATISTICS;
SQL> WITH rslt AS (
  2    SELECT c.empno, c.ename,
  3          (SELECT a.empno
  4           FROM   emp a
  5           WHERE  a.privs = 'Y'
  6           START WITH a.empno = c.mgr
  7           CONNECT BY PRIOR a.mgr = a.empno
  8           AND PRIOR a.privs != 'Y') AS nearest
  9    FROM   emp c
10    WHERE  c.privs = 'Y')
11  SELECT empno, LPAD (' ', (LEVEL - 1) * 2) || ename ename
12  FROM   rslt
13  START WITH empno = 7839
14  CONNECT BY PRIOR empno = nearest;
     EMPNO ENAME
      7839 KING
      7698   BLAKE
      7499     ALLEN
      7521     WARD
      7654     MARTIN
      7844     TURNER
      7900     JAMES
      7782   CLARK
      7934     MILLER
      7788   SCOTT
      7876     ADAMS
      7902   FORD
      7369     SMITH
13 rows selected.
Statistics
          2  recursive calls
          8  db block gets
       2011  consistent gets
          1  physical reads
        648  redo size
        698  bytes sent via SQL*Net to client
        508  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         18  sorts (memory)
          0  sorts (disk)
         13  rows processed
SQL> SELECT empno, LPAD (' ', (LEVEL - 1) * 2) || ename ename
  2  FROM  (SELECT empno, ename, RTRIM (SUBSTR (path, 1,
  3                  INSTR (path, '/', -1)), '/') path
  4         FROM  (SELECT empno, ename, SYS_CONNECT_BY_PATH (
  5                       DECODE (privs, 'Y', empno), '/') path
  6                FROM   emp
  7                WHERE  privs = 'Y'
  8                START WITH empno = 7839
  9                CONNECT BY PRIOR empno = mgr))
10  START WITH empno = 7839
11  CONNECT BY PRIOR empno = SUBSTR (path, INSTR (path, '/', -1) + 1);
     EMPNO ENAME
      7839 KING
      7788   SCOTT
      7876     ADAMS
      7902   FORD
      7369     SMITH
      7698   BLAKE
      7499     ALLEN
      7521     WARD
      7654     MARTIN
      7844     TURNER
      7900     JAMES
      7782   CLARK
      7934     MILLER
13 rows selected.
Statistics
          1  recursive calls
          0  db block gets
        112  consistent gets
          0  physical reads
          0  redo size
        698  bytes sent via SQL*Net to client
        508  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
         40  sorts (memory)
          0  sorts (disk)
         13  rows processed
SQL>

Similar Messages

  • GET PERNR skips some employees in the report

    Hi all.
    This is my first post in this forum. I'm beginner in ABAP programming and I've got a issue in my report that I don't succeed in solving it.
    In the first line of the source code, within the start-of-selection event, I use the GET PERNR command to bring the employee personnel numbers. While I was debugging I've noted this command was skipping some employees. There isn't any line of code before the GET PERNR.
    Do you have any ideia about what's happening?
    Thanks in advance.
    Tiago.

    HI Tiago,
    here is another probably cause. The dates. It´s important that the employees,
    are active in the infotype(I think that is Infotype 0), in the dates that check your program. It´s useful to know
    the selection data period (pnpbegda/pnpendda), the employees selection data (pnpbegps/pnpendps), the radiobutton selection data (pn-begda/pn-endda), of the pnp logical d.b.selection screen. You can see the values of these fields debbuging Ah!, another point, start-of-selection & Get pernr, are differents events in the execution of an abap program.
    Hope this lines help you!
    Carles

  • Can I use Microsoft Project Professional to connect hyperlink a some documents in the server of our company?

    Just like the titre,
    Can I use Microsoft Project Professional to connect hyperlink to some documents in the server of our company?  I want to share some documents not in my computer, which is in the server of our company. 

    Hello,
    Sure you can, right click on required task that relates to the document, at the bottom on that menu you will see "Hyperlink". Click Hyperlink and a new window will open, in the new window in the "address" field type or paste in the web address / file share
    address etc. Click OK then you will see a web link appear in the indicator column.
    Paul
    Paul Mather | Twitter |
    http://pwmather.wordpress.com | CPS

  • I want to skip some html code part when refersh the page, how can we know

    Hi,
    i want to skip some html code part when refersh the page, how can we know when we pressed refresh button or F5 key
    thanks in advance....

    There's not really any simple way to do this. Maybe tracking the page the user should be one from every page in the site and if the page being accessed is the same as the last one accessed, assume it was a refresh.

  • Unicode test conversion - skip some steps?

    Hi all,
    We will be upgrading our system from R/3 4.7x200 to ERP2005, and we have recently successfully upgraded our sandbox R/3 4.7x200 system to ERP2005, all pretty much without too much of a hassle. Now we are planning to do a unicode conversion on the same sandbox system, to get some idea about the runtime of such a conversion. The problem is that we are short on time, and I wonder what the effects will be if I skip some of the steps that should be done before we begin with the actual conversion phase (R3load). I have done some of the pre-conversion steps, but not all, and I wonder if there are some that I absolutely MUST do in order to get through the actual conversion?
    In the end, we are not looking for a functioning system after this test conversion, we are only interested in the runtime and downtime findings.
    Regards,
    Thomas

    Hi,
    You cannot skip same conversion step.
    the good ideas is to use the released method by SAP to do upgrade/conversion at the same time. this will save you time.
    check OSS note
    Note 928729 - Combined Upgrade & Unicode Conversion FAQ
    Good Luck

  • Windows Phone Emulator is unable to connect to the Windows Phone operating system: The phone did not respond to the connect request. Some functionality might be disabled

    We are receiving following error, while trying to deploy the application on Win Phone emulator. “Windows Phone Emulator is unable to connect to the Windows Phone operating system: The phone did not respond to the connect
    request. Some functionality might be disabled.”
    I have tried all possible ways that we found on blogs. We are still not able to solve this issue

    I have had a lot of issues with the emulator in the past.
    Check out this troubleshooting guide. It might help:
    https://msdn.microsoft.com/en-us/library/windows/apps/jj681694(v=vs.105).aspx
    Also, I find that if I cancel my build/deploy while it is stuck on booting the OS and then wait a short while the phone OS will complete booting, and from that point I can deploy to the emulator. It's a workaround, but it works well for me.
    I need to do that on Windows 10 tech preview, which may or may not be simply an incompatibility with the beta OS.
    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

  • Script single button to play frames, then skip some, and continue play?

    Just as the topic says, I want to script a button to go to
    and play through a motion tween, but then skip some frames to then
    play another motion tween all in one button press. For example,
    play frame 1 which plays the tween and ends at frame 10 (I have
    that part down fine) but then for it to skip ahead to continue to
    play frame 20 and then of course stop once it finishes that motion
    tween.
    Tried a few searches but its too many words to explain so I
    wasnt finding anything. Its probably a simple command im just not
    familiar with yet. Can anyone help?

    I probably should have been more specific. I cant add
    anything to the timeline because I have multiple buttons using the
    first tween, which is a fade out. Thats why I need a script to add
    to each button only to play through that first common tween, and
    then skip to play an individual tween set for each button. Like
    button 1 goes through the first common tween, a fade out (plays
    frames 41 - 53) and its individual tween is frames 54 - 66. This
    works fine of course because the tweens are next to each other.
    Button 2's individual tween starts on frame 67, so it needs to play
    through the common tween fade (41 - 53) skip Button 1's frames, and
    continue play on 67. These buttons are located on frame 1 (main
    menu) so is it even possible to script a button to do such a thing?
    I figured there would be but nothing im trying or seeing online is
    working. Heh... does this make sense? :o
    The only other way I know it will work is if I copy and paste
    all the information in the layers before each section but that
    causes me to have to push a lot of information further down the
    timeline, kinda making a big mess and causing me to rescript all
    frames there.

  • My ISP requires a http login. I can use the iPad fine if I am logged in on a PC connected to the same wifi network, but if I login on safari on my ipad, the connection drops after some time.. any workaround?

    My ISP requires a http login. I can use the iPad fine if I am logged in on a PC connected to the same wifi network, but if I login on safari on my ipad, the connection drops after some time.. any workaround?

    TJBUSMC1973 wrote:
    The iPhone is working, as designed and advertised.  In this case, the user failed to educate themselves properly, either by proper research or asking the right questions, before purchasing the device.
    I understand that the OP failed to do research. But then, I wasn't replying to the OP. I was replying to Chris. I have Verizon. I can talk and use data at the same time with my Droid Maxx. Therefore, the problem is not just with the network. It would be technically possible for an iPhone to do that on Verizon/Sprint if Apple had chosen to use a different chip, such as the kind other phone manufacturers have elected to use.
    Of course, this is probably all irrelevant to the OP's issue. It was merely a point of clarification, especially for those people who are used to being able to use both voice and data at the same time on Verizon. When they switch to an iPhone, they are often surprized at the limitation.
    Best of luck.

  • 3 BUGS  WITH LION CONNECTING PROBLEMS TO SOME WEB SITES & MAIL SERVERS

    I HAVE 3 BUGS  WITH LION FOR MORE THAN ONE MONTH & GETTING WORSE
    1 - CONNECTING PROBLEMS TO SOME WEB SITES  SERVERS
    I TRY  EVERY BROWSER I HAVE ( SAFARI \ FIREFOX \ CHROME )
    I CAN NOT OPEN SOME SITES ALMOST ALL TIMES
    SOME TIMES OPEN THIS SITES BUT AFTER MINUTES DO NOT CONNECT TO IT
    I GET THIS BUG IN THE PAST  BUT LATLY IT GONE WORSE
    NOW IT IS MORE FREQUENT  & MORE  SITES
    2 - CONNECTING PROBLEMS TO SOME MAIL SERVERS
    THE MAIL APP CAN NOT CONNECT TO
    ( INCOMING  HOTMAIL SERVER \  OUTGOING  HOTMAIL SERVER \  OUTGOING  YAHOO SERVER  )
    MOST OF THE TIME
    MORE FREQUENT
    3 - CHECKING OUT SHOPPING BAG FROM SHOPPING SITES PROBLEMS
    I TRY TO CHECKOUT THE SHOPPING BAG IN 2 SITES & COULD NOT CHECKOUT THE ORDER 
    I HAD TO USE ANOTHER COMPUTER
    FIRST TIME I HAVE THIS
    I HAVE LITTLE SNITCH 3 ON & LION FIREWALL ON
    I TRIED EVERY ACCOUNT  IN THIS COMPUTER
    with Little Snitch disabled   >>>>>>>  i have the same problem !!!!!
    with lion firewall off    >>>>>>>  i have the same problem !!!!! 
    I STILL HAVE THE SAME CONNECTION PROBLEM
    IF YOU HAVE ANY SUGGESTION PLEASE HELP ME
    LION  BUGS IS DRIVING ME CRAZY   IT IS BY FAR THE 2ND WORSE OS Produced by APPLE AFTER IOS 2.0 FOR IPHONE
    I WANT TO GO TO LEOPARD AGAIN
    IF YOU HAVE ANY IDEA HOW TO INSTALL LEOPARD TO THE NEW MACBOOK PRO
    PLEASE LET ME KNOW

    Biggest bug is that your key caps key gets stuck. Repost, without the all caps stuff, which is tantamount to shouting, and maybe we can read what your problems are all about.

  • I can not connect to iswifter, some times it is connected and some time it shows " UNABLE TO CONNECT TO SERVER PLEASE CHECK THE INTERNET" but my internet connection is good and other wbe site i can open without any problem. Please guide  me..

    I can not connect to iswifter, some times it is connected and some time it is not connected and getting message " UNABLE TO CONNECT TO SERVER , CHECK YOUR INTERNET" but my internet connection is ok and I can open other web site with out any problem.  Please guide me how to solve this issue.

    Can't connect to the iTunes Store
    http://support.apple.com/kb/TS1368
     Cheers, Tom

  • My iPod nano skips some songs for no apparent reason

    When i try to play songs on my iPod nano 7th gen, it skips some of them without playing.
    The album art and track name shows up for a split-second and then it goes to the next track. Sometimes it skips several tracks by the same artist at a stretch. The songs the ipod keeps skipping play perfectly on iTunes. I tried erasing all the songs and sopying them again, but it didn't solve the problem. (I haven't tried restoring the ipod yet)

    Hi there,
    You may want to check and see if the shake to shuffle feature is enabled. Take a look at the article below for more information.
    iPod nano: About Shake
    http://support.apple.com/kb/HT2907
    Griff W.

  • TS3048 My bluetooth mouse usually loss with unknown reasons and it then automatic connected again after some clicks.

    Dear Sir or Madam,
    I have bough my Macbook Pro since 8 months ago and it seams quite good upto now, however in these days my Bluetooth mouse ussually lossed with unknow reasons and it then automatic connected again after some clicks.
    I have check mouse battery as well as relevent reasons like turn-on, but it still repeated and I don't know what is exact problem, it due to my mouse or my mac?
    Thank you very much and looking forward to your help.
    BR

    Check your Bluetooth, do you have a bunch of stuff listed in there that you are no longer using?
    Or another peripheral you stored away in a cabinet near by?

  • SQL Skips some records

    Respected,
    About Server:
    I have installed SQL Server 2012 Standard Edition in a Server.
    I have deployed 4 live databases in SQL Server 2012 and one live portal in IIS. (and a few other applications).
    Problem:
    In the last deployed database(4th ), when I process update operation(i.e., batch of more than 200000 records). It skips some update operations.
    If I process single record which was skipped in batch again then it works okay.
    Kindly let me know the solution asap.
    Regards,
    Pravin

    Hi Aequitas,
    You can try using Transaction at application level or at DB level to ensure that the update operation was successfully completed.
    http://technet.microsoft.com/en-us/library/ms174377.aspx
    Moreover please review the update criteria. It is also possible that rows are skip due to the criteria while updating. Lastly ensure that table/rows are not locked while updating at the application level.
    Regards, RSingh

  • Photo stream skipping some pictures....

    Hi! I'm saving from Lightroom to the folder where I want to get the pictures streamed to my iPhone.... most of the time it works, but there are some pictures that don't want to transfer, unless I move them out of the folder and put them back in, some times not even doing that helps, it will just skip the photo.....   I'm exporting all the photos in a size of 2500 Pixels wide, all with the same preset..... any ideas? of just a bug????

    Welcome to the Apple Community.
    All photos taken on the phone go to the camera roll. If photostream is enabled they should also go to photostream in addition to photos added from other devices. Photos added to photostream from other devices will not be added to the camera roll on your phone (unless you move them manually.
    Photos taken on the phone should be added to camera roll immediately, it may take a few moments before they appear in photostream, while they are sent from the camera roll to the cloud and back again to photostream.
    If photos aren't being added to photostream there may be a couple of reasons:
    Photostream only syncs photos over Wi-Fi, make sure you are connected to Wi-Fi to begin with.
    Photostream only syncs when the camera app is closed, ensure it is closed.
    Photostream only syncs when the battery is above 20%, try recharging the device
    If the problem persists:
    Try disabling photo stream on your device (settings > iCloud), restarting your device and then re-enabling photo stream.
    If this doesn't help you may need to reset photo stream. You can do this at icloud.com by clicking on your name in the top right corner and then the advanced settings in the pop-up dialogue box that appears.
    Note: disabling photostream and re-enabling it will result in any photos that are currently in the photostream album on your device, that are older than 30 days old, not being added back.

  • Moto Bluetooth headphones connect but skipping makes then useless

    After upgrading to Leopard, I was excited to be able to use my Moto Headphones, but after pairing them the skipping is so bad they are pretty much useless. I am a Mac newbie, os maybe I am missing some important setting, but thus far I have not been able to fidn anything that helps. I have a Mac Mini and am also using BT Keyboard and Mouse (both Apple). I have seen some issues with having multiple BT devices connected. Is it not possible to use all 3 of these devices at the same time? If it comes down to it, I guess I could do without the keyboard and mouse (ummm, not). I love having the wireless KB and Mouse, and I am not willing to part with them, but it would be nice to get this working.

    Nobody else has this issue?

Maybe you are looking for

  • How do I move apps from an old mac to a new one

    I am purchasing a new Macbook Pro after having my old one for six years. I have numerous apps that I have purchased and downloaded over the years. I don't want to loose them and really don't want to have to purchase them again. Can I and how can I mo

  • Please help me! To Install solaris 8 on Intel plateform

    Hi All, During when I tried to install Solaris 8 on my machine I repetadely used to encountered following problem listed below.I have also checked my motherboard's chipset with Sun's Hardware Compatiability List, it is there. My Machine: Intel PIII M

  • Clustered column charts

    how do you put a space in between two columns in a clustered columnset?

  • Moving iPhoto images to PC

    How can I transfer images and videos in iPhoto'11 (in Mac running OS X) to Adobe Photoshop Elements on a PC running Windows 7?

  • Why MetalSplitPaneDivider is not a public class?

    Dear All, The MetalSplitPaneDivider is not a public class because of that, I am not able to extend it to give a custom implementation. My requirement is that, whenever the leftButton is pressed, it should not go the 0 position, instead I have to have