CONNECT BY - Start from different levels

Hello again,
It's me again with a hierarchical query on which I'm stuck...
I think, the easiest way to understand my issue is to get an example:
DROP TABLE my_organisations;
CREATE TABLE my_organisations
  org_id NUMBER(10),
  org_name VARCHAR2(100),
  parent_org_id NUMBER(10),
  is_modified NUMBER(1)
INSERT INTO my_organisations VALUES(1, 'Top organisation', null, 0);
-- first department
INSERT INTO my_organisations VALUES(362, 'HR', 1, 0);
INSERT INTO my_organisations VALUES(11, 'Recruitment', 362, 0);
INSERT INTO my_organisations VALUES(119, 'Local Recruiment', 11, 1);
INSERT INTO my_organisations VALUES(192, 'Remote recruitment', 11, 0);
-- second department
INSERT INTO my_organisations VALUES(1000, 'SALES', 1, 0);
INSERT INTO my_organisations VALUES(1101, 'Local Sales', 1000, 0);
INSERT INTO my_organisations VALUES(1102, 'Remote Sales', 1000, 0);
INSERT INTO my_organisations VALUES(9452, 'Brazilian Sales', 1102, 1);
INSERT INTO my_organisations VALUES(9992, 'Mexican Sales', 1102, 1);
INSERT INTO my_organisations VALUES(9110, 'Japanese Sales', 1102, 0);
INSERT INTO my_organisations VALUES(1103, 'Lost', 11, 0);
-- thirst department
INSERT INTO my_organisations VALUES(333, 'IT', 1, 0);
INSERT INTO my_organisations VALUES(444, 'Helpdesk', 333, 0);
INSERT INTO my_organisations VALUES(555, 'Hardware', 444, 0);
INSERT INTO my_organisations VALUES(666, 'Software', 444, 0);
INSERT INTO my_organisations VALUES(777, 'Microsoft', 666, 0);
INSERT INTO my_organisations VALUES(778, 'Linux', 666, 0);
INSERT INTO my_organisations VALUES(788, 'MAC OS', 666, 0);
INSERT INTO my_organisations VALUES(888, 'Windows', 777, 0);
INSERT INTO my_organisations VALUES(999, 'XP', 888, 1);
INSERT INTO my_organisations VALUES(1111, 'MAC', 555, 0);
COMMIT;I have a hierarchical structure store in the my_organisations table. The parent child relation is made using parent_org_id. As you can see in my table definition, I have a flag is modified. That flag can be set at any level in the hierarchy.
I would like to have a statement that returns all the modified organisations with all their hierarchy (ascendants and descendants). Is this possible without having to write PL/SQL procedure?
I have no idea how to start. If I have a SELECT ... CONNECT BY... START WITH is_modified = 1, I only have the modified nodes and then I can get ascending nodes. But I have no idea how I can get the whole hierarchy of a node...
Can anyone help ?? (Im using 10g)
Thanks,

Hi,
Stew Ashton wrote:
Adding a few details to Frank's idea, just to get things sorted reasonably:To really get things sorted correctly, I think you'll have to do yet another CONNECT BY, on the result set of the UNION:
WITH     universe     AS
     SELECT     *          -- Get modified nodes and descendants 
     FROM     my_organisations
     START WITH     is_modified     = 1
     CONNECT BY     parent_org_id     = PRIOR org_id
             UNION
     SELECT     *          -- Get ancestors of modified nodes
     FROM     my_organisations
     START WITH     is_modified     = 1
     CONNECT BY     PRIOR parent_org_id     = org_id
SELECT     org_id
,     LPAD ( ' '
          , 2 * (LEVEL - 1)
          ) || org_name     AS org_name
,     parent_org_id
,     is_modified
,     LEVEL
FROM     universe
START WITH     parent_org_id     IS NULL
CONNECT BY     parent_org_id     = PRIOR org_id
;Output:
ORG_ID ORG_NAME                  PARENT_ORG_ID IS_MODIFIED LEVEL
     1 Top organisation                                  0     1
   333   IT                                  1           0     2
   444     Helpdesk                        333           0     3
   666       Software                      444           0     4
   777         Microsoft                   666           0     5
   888           Windows                   777           0     6
   999             XP                      888           1     7
   362   HR                                  1           0     2
    11     Recruitment                     362           0     3
   119       Local Recruiment               11           1     4
  1000   SALES                               1           0     2
  1102     Remote Sales                   1000           0     3
  9452       Brazilian Sales              1102           1     4
  9992       Mexican Sales                1102           1     4

Similar Messages

  • I was at level 111 on My Tom app, but when i've changed my i Phone it starts from 1st level. How can i get back my level?

    I was at level 111 on My Tom app, but when i've changed my i Phone it starts from 1st level. How can i get back my level?

    "When you changed your iPhone".  Do you mean you purchased a new phone? If that is the case, did you restore the new phone from a backup of the old phone? Is it possible that the app you are using does not save data in the iPhone backup? Have you contacted the app developer to ask them about it?

  • Error when connecting to MDM from different lan

    Hi,
    I got "Image Server Login Error" when connecting with client to server from different LAN, server is up, and i can connect to it when i in the same LAN. Ports 20003, 20004, 20005 for MDM server discovering and repository port 2345 is accessible through router. Running SP2 5.5.24.06.
    Rem: it's not a port problem, when port 2345 is closed i got "WinSock error on connect"
    PS: When I used MDM SP1 i connected to him properly in the same case.

    Hi Dmitry,
    If your repository is set to port 2345, then 4 subsequent ports should be openned also, i.e. 2346-2349.
    Regards, Lev

  • Outside in Viewer resets the page number to 1 always, even though the Word document has page numbering starting from different value.

    Hi All,
    I've a Word Document with page header having page number inserted.However the page numbers have been formatted to start from a value other than 1.
    E.g. For a given word document, navigate to "File -> Insert -> Page number-> format page number -> start at " and set the value to say "300". Now insert page numbers, so that the page numbering of the 1st page starts from 300.
    When this document is viewed using Outside-in Viewer, the page number of the 1st page always shows 1 instead of showing 300 (though this is not being reset/changed within the actual document)
    I'm using Outside in 8.1.9 SDK for the same. Is there an API to set the page number correct (exactly what has been set within the original document) while viewing...
    Alternatively confirm if this is a limitation within the Outside-in Viewer.
    Thanks,
    Badri

    You're going to need to open an SR to Outside In Support, Product ID 2276.
    Make sure you attach an example Word doc to the SR.

  • How to find the number of users  connected to database from OS level(Linux)

    Hi All,
    Could anyone know , how to find the number of users connected to database without connecting with sql*plus
    is there any command to find it?
    example we have 10 databases in one server, how to find the number of users connected to particular database without connecting to database(v$session)?
    oracle version:- 10g,11g
    Operating System:- OEL4/OEL5/AIX/Solaris
    any help will be appreciated.
    Thanks in advance.
    Thank you.
    Regards,
    Rajesh.

    Excellent.
    Tested, works as long as you set the ORACLE_SID first ( to change databases )
    ps -ef | grep $ORACLE_SID | grep "LOCAL=NO" | awk '{print $2}' | wc -l
    Thanks!
    select OSUSER
        from V$SESSION
    where AUDSID = SYS_CONTEXT('userenv','sessionid')
        and rownum=1;Best Regards
    mseberg

  • Show data from different levels of hierarchy in a report

    Hi,
    We have to show Budget Vs Actual for sales. We have multiprovider on two cubes (Plan & Actual).
    We want to report using Customer Hierarchy.
    Customer hierarchy is like -
    Level 1
    ---> Level 2
    > Level 3
    > Level 4
    > Customer1
    > Customer2
    > Customer3
    > Customer4
    Actual data is avbl  at Customer but Budget is at avbl only upto Level1 or 2 . 
    Budget Infocube structure
    Level1     Level2     Material     Calmonth          Sales QTy
    Actual Infocube structure
    Customer     Calmonth     Material          Sales Qty
    So how to create a BEx query so that I can show Budget Vs Actual for avaialble data?
    If I drill down uptp Level2 it will show Budget Vs Actual and for further drill downs only actual data.
    Thanks,
    Vikram.
    Edited by: Vikram Kate on Jan 2, 2011 12:46 AM

    Any suggestion/ idea pls.
    I am sure this is a valid requirement. If anyone know how to do it,  pls let me know.
    Edited by: Vikram Kate on Jan 21, 2011 1:04 PM

  • Business Objects XI 3.0 connecting to domains from different forest

    Hi All,
    Does anyone know if BOE XI 3.0 support AD authenication with multiple AD domains which reside in different forrests?
    I found other post which mention we are now supporting it in XI 3.0 SP1 but I couldn't find any document on it.
    Thanks,
    Bobby

    3.1 or 3.0 SP1 both support multiple forests. There are rules, there must be a transitive full two way trust between the forests.
    i.e. in order to map groups the CMS needs to query the remote forest so the remote forest(s) must trust the local one.
    In order for remote users to login to the local forest they must trust the remote one(s)
    The changes were made in the AD plugin (basically we query multiple global catalogs and lookup objects by DN as opposed to SID) So there is no configuration needed in BO.
    Regards,
    Tim

  • Our etext output needs a combination of XML tags from multiple levels

    Our etext output needs a combination of XML tags from multiple levels. Each unique combination of <OutboundPayment>/<Payee>/<SupplierNumber> and <OutboundPayment>/<DocumentPayable>/<ReferenceNumber> needs to be on a unique line. That means we need to combine information from different levels into a single e-text line before there is an end of record.
    Right now, it pulls the supplier number for the first invoice and matches it up to the proper line, but each line after that just repeats the supplier number it pulled the first time and uses that on each line matched to the different invoices instead of looping back and picking up the correct supplier associated with each invoice in the Format Payments Instructions.
    I have Oracle Support trying to resolve this in an SR, but so far they have made no progress. Has anyone else done this before? What command do I need to use to combine these two levels into one line of output.
    If I create a header line just above the detail line just for the supplier number it gives me exactly what I need, but on two lines in the etext output. I need it all on a single line.
    Thanks.

    If anyone needs the solution, I finally have it:
    I created a level for grouping criteria as PaymentReferenceNumber/Payee/Address/AddressName, DocumentInternalIDSegment2, called InvoiceDetailLevel. The base level is OutboundPayment.
    I then added a level (InvoiceDetailLevel) between OutboundPaymentInstruction and the DocumentPayable level.
    Then in the syntax for the supplier number and the address I entered this in the Data column:
    ../../ OutboundPayment/Payee/SupplierNumber
    and
    ../../ OutboundPayment/Payee/Address/AddressName
    That did the trick and now it is working correctly on every line, looping back to get the proper information.

  • Processes from different zones

    Hi,
    If processes with the same names are started from different non-global zones, what is the way to identify that a pid is for a process in certain zone? ps -lef does not show the zone in which the process is started. Is there any other option to ps?
    Thanks!

    On my b63 system, the ps man page shows (among others) the following options:
    -z Lists only processes in the specified zones. Zones can
    be specified either by name or ID. This option is only
    useful when executed in the global zone.
    -Z Prints the name of the zone with which the process is
    associated under an additional column header, ZONE.
    On my system,it looks like:
    bash-2.05b# ps -efZ|grep bash
    global root 20842 20804 0 23:27:58 pts/1 0:00 bash
    demo1 root 28583 21932 0 Oct 01 zoneconsole 0:00 bash
    ldaptest root 7090 7063 0 Oct 03 zoneconsole 0:00 bash
    foo root 257 247 0 Sep 25 zoneconsole 0:00 bash
    global root 20804 20800 0 23:17:52 pts/1 0:00 bash
    ldap2 root 7340 7314 0 Oct 02 zoneconsole 0:01 bash
    Sun has done a very good job with updating the man pages of commands that
    are zone aware, don't be afraid to use them. :-)
    Hi,
    If processes with the same names are started from
    different non-global zones, what is the way to
    identify that a pid is for a process in certain zone?
    ps -lef does not show the zone in which the process
    is started. Is there any other option to ps?
    Thanks!

  • How to join tables from different databases (DBLink/DB connection )

    Hello,
    i have an issue and i hope you could help me to solve it. My problem is: I want to create native sql select which joins two tables from different DB (both of them are ORACLE, one of them internal, another one - external). I have found several notes and posts, but without any success. Db connection exists in dbcon table, so this part of my problem has been solved.
    I would like something like that:
    select * from table1@xxx inner join table2.
    i can not split this select into two separate ones, because both tables store over 30 mln. entries and i do not want to create any copies of them.
    Br,
    dez

    Hi,
    you might need to create a DB-Link on DB level and use EXEC SQL.
    Lots of stuff on google about this, like
    Oracle DBLink ( external database )
    Volker

  • Is it too much to ask from apple, an option for different volumes levels from different apps, including alarm, text, email, basically from every posible app?

    Is it too much to ask from apple, an option for different volumes levels from different apps, including alarm, text, email, basically from every posible app?

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • "Getting started"  for connectivity to OAM from OSB

    I am completely new to OAM IdXml. I need to do POC to make connectivity to OAM for CRUD operations from OSB.
    Where can I start from? Is there any "Getting started" Guide or Any beginer steps to follow to get started?

    I'm very familiar with organizing in iTunes, and I prefer to have iTunes organize my library and COPY any media I add (that way I don't have links to media everywhere).
    iTunes and iPhoto are totally different except that they both start with "i"
    (1) linking to my existing folders and photos
    Advantages:
    Keeping the library file small (so as to keep iPhoto speedy to open/navigate?)
    Preserve folder structure
    Drawbacks:
    Can't remove pics from the hard drive after I've previewed in iPhoto. I would have to preview all the pics in my respective folders, remove the ones I don't want, then import and tag, etc.
    Additional major drawbacks
    In addition to the more difficult import workflow as you note above deleting photo is more difficult (delete in iPhoto and then again from the hard drive outside of iPhoto)
    And upgrading/replacing hardware is much more difficult
    (2) copying the media to the iPhoto Library file. I like this idea because I can "Show package contents" if I want to see my originals, and it keeps everything in a nice, tidy file.
    Drawback (possible): Does this file, when it gets large, take a long time to open, and does iPhoto slow to a crawl? (I have about 80 GBs of photos to import).
    Advantage: I can remove files from the hard drive right from within iPhoto.
    That is a large library - mine has just over 30,000 photos in it which consist of about 50GB of photos (total library is about 72GB) which runs great on a 27" iMac (was getting slow on my old G5 before upgrading to an Intel 3.33 GHz core 2 duo)
    LN

  • SQL Query to Roll up amounts starting from a lower to higher level

    with data as (select 'C' Child, 'P' as parent, 11 amount from dual
      union all select 'C1', 'C', -2 from dual
      union all select 'C2', 'C', 3 from dual
      union all select 'C3', 'C', -8 from dual
      union all select 'C4', 'C', 10 from dual
      union all select 'C11', 'C1', 7 from dual
      union all select 'C12', 'C1', 12 from dual
      union all select 'C21', 'C2', 5 from dual
      union all select 'C22', 'C2', 9 from dual
      union all select 'C31', 'C3', 6 from dual
      union all select 'C32', 'C3', -4 from dual
      union all select 'C41', 'C4', -3 from dual
      union all select 'C42', 'C4', 13 from dual
      union all select 'C111', 'C11', 16 from dual
      union all select 'C121', 'C12', 8 from dual
    ) Select * from data order by 2
    Hi Experts,
    I have the following table with parent child relationship which I would like to roll up starting from a lower to a higher level. The catch here is as I move up the level i should replace the amount for a parent with the aggregate value of its children and grand total aggregated amount should be in C
    For example; In the given sample data c111 rolls up to c11 as 16 (please note: the amount for c11 is 7 should not be added to 16 rather replaced by 16) which should further roll up to c1.
    This means c1 = c11c12; c11 = c111 = 16 so, c1= 1612 instread of 16712.
    Since this is a interim table, i do not have any control on how many levels it might contain.
    So dynamically, i need a query which would rollup and aggregate the amount from a lower to a higher level moving up from the bottom.
    Is this possible? I look forward to all the help. Thanks in advance.

    SQL> with data as
      2  (
      3    select 'C' Child, 'P' as parent, 11 amount from dual
      4    union all select 'C1', 'C', -2 from dual
      5    union all select 'C2', 'C', 3 from dual
      6    union all select 'C3', 'C', -8 from dual
      7    union all select 'C4', 'C', 10 from dual
      8    union all select 'C11', 'C1', 7 from dual
      9    union all select 'C12', 'C1', 12 from dual
    10    union all select 'C21', 'C2', 5 from dual
    11    union all select 'C22', 'C2', 9 from dual
    12    union all select 'C31', 'C3', 6 from dual
    13    union all select 'C32', 'C3', -4 from dual
    14    union all select 'C41', 'C4', -3 from dual
    15    union all select 'C42', 'C4', 13 from dual
    16    union all select 'C111', 'C11', 16 from dual
    17    union all select 'C121', 'C12', 8 from dual
    18  )
    19  , data1
    20  as
    21  (
    22    select parent
    23         , child
    24         , lpad('-', (level-1)*3, '-') || parent tree_structure
    25         , amount
    26         , case when connect_by_isleaf = 1 then amount else 0 end amount_leaf
    27      from data
    28     start with parent = 'P'
    29   connect
    30        by parent = prior child
    31  )
    32  select parent as node
    33       , tree_structure
    34       , amount_sum
    35    from data1
    36   model
    37   dimension by
    38   (
    39      child
    40    , parent
    41   )
    42   measures
    43   (
    44      amount_leaf as amount
    45    , tree_structure
    46    , 0 amount_sum
    47   )
    48   rules automatic order
    49   (
    50      amount_sum[any,any]= amount[cv(),cv()] + nvl(sum(amount_sum)[any, cv(child)],0)
    51   );
    NOD TREE_STRUCTURE            AMOUNT_SUM
    P   P                                 50
    C   ---C                              24
    C1  ------C1                          16
    C11 ---------C11                      16
    C1  ------C1                           8
    C12 ---------C12                       8
    C   ---C                              14
    C2  ------C2                           5
    C2  ------C2                           9
    C   ---C                               2
    C3  ------C3                           6
    C3  ------C3                          -4
    C   ---C                              10
    C4  ------C4                          -3
    C4  ------C4                          13
    15 rows selected.

  • OBIEE report from multiple facts at different levels

    Currently we need to develop a report with columns from 3 different facts surrounded with conformed and non conformed dimensions at different levels.
    After setting the hierarchial levels and putting the facts into single logical table with different sources OBIEE is generating 2 different queries and does a full outer join.
    I would like to know how we can do a left outer join instead of full outer join between the 2 queries based on a common column?
    Thanks in advance.

    Hi Vinod,
    The scenario provided in the link above doesnt match to my issue.
    We need to develop a report from multiple fact tables at different levels with conformed & non conformed dimension columns.
    I have 7 dimensions D1, D2, D3, D4, D5, D6 and D7 & two fact F1 and F2 tables.
    F1 is tied to dimensions D1,D2,D3,D4,d5
    F2 is tied to dimensions D3,D4,D5, D6 and D7.
    In my report I have columns from D1, D2, D3, D4, D5, D6, D7, F1 and F2.
    So OBIEE generates 2 queries with columns from D1,D2,D3,D4,d5 & F1 measure and another query with D3,D4,D5, D6, D7 and F2 measure.
    and then does a cross fact join out of box between 2 queries.
    But I need to do a left outer join between the 2 queries on a common column instead of cross fact join. I would like to know how we can achive this.
    Thanks.

  • HT201250 i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. do i keep my files in the portable hard disk when I connect it again with the macbook or the time machine will era

    i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. Am i keeping my files in the portable hard disk when I will connect it again with the macbook or the time machine will erase all?
    I would like to know if after I erase all my data, empy hard drive inside the macbook, the time machine will erase all my files that I have saved in my "WD "My passport" external hard drive

    Welcome to Apple Support Communities
    Time Machine has to erase the external disk in order to make backups. Before setting Time Machine up, copy the files of your external disk to the hard disk of the Mac in order not to lose them, and then, set up Time Machine. The first backup will start automatically.
    If you want more information about Time Machine, read the Pondini's site > http://pondini.org

Maybe you are looking for

  • HTTPInvoker does not WORK!!!

    Hi, i have a problem access my JBOSS thru firewall, i have followed the instruction from the link below but unfortunately no luck! My arhitecture is exactly same as the diagram in link specified below. http://www.nemesisit.ro/opendocs/simplearch/simp

  • Infotypes special characters are not displayed correctly

    hi experts,               While entering names with special characters in infotypes it happens that some of them are not correctly displayed . can you please help me out as soon as possible thnx harish

  • My USB port wont work and computer is almost brand new

    I have plugged in my iPhone 4 and synced it with my Macbook Pro when I first got it, now when I just tried to plug in a iPhone 5 it says there is a USB device already plugged in taking too much power and once it is unplugged my other USB devices will

  • Freezing, glitches and weird graphics problems

    My white iMac starting having weird praphics issues about year and a half ago. Nothing that was too much to deal with. Simply using expose always cleared it up and if it came back I would do the same. It seems to be getting worse. And then yesterday

  • Cant Get Mail

    When I try to open my iPad mail, I get the message "Connection to the server failed". Can anyone help me out here please?