application of the hierarchy with the dynamic start condition

Hello

I have a table that stores line items (foohierarchy) and other storage users and items (useritems). Unfortunately, it is not consistent and is missing some entries. I would like to correct this using pure sql. Fixing here means that a user who has a certain child element must also have parents of this child. However, there are a few obstacles here. First the hierarchy table does not explicitly which elements are higher level items. I'm trying to fix this by emulating an adequate structure and named this fixedhierarchy. A select statement that returns only designed relations users/article would be nice.
Here a few visualization and sample data, sample data follows the model that each element uses its level that its suffix, but this should not be exploited in the statement:

art of ASCI:
-- A1 (peter,paul)
--   \_ B2
--   \_ C2
--        \_D3 (thomas)
--            \_X4
-- E1
--   \_F2
-- G1
--   \_H2 (heidi)
examples of data
drop table foohierarchy;
drop table useritems;

create table foohierarchy (
child_item varchar2(30),
parent_item varchar2(30));


insert into foohierarchy values ('B2','A1');
insert into foohierarchy values ('C2','A1');
insert into foohierarchy values ('D3','C2');
insert into foohierarchy values ('X4','D3');
insert into foohierarchy values ('F2','E1');
insert into foohierarchy values ('H2','G1');

create table useritems (
username varchar2 (40),
item varchar2(30)
);

insert into useritems values ('peter','A1');
insert into useritems values ('paul','A1');
insert into useritems values ('thomas','D3');
insert into useritems values ('heidi','H2');

commit;
my attempt at fixing the hierarchy table
with fixedhierarchy as
(select parent_item,child_item from foohierarchy
union all
select distinct null parent_item,parent_item child_item from foohierarchy where parent_item not in (select child_item from foohierarchy))
select * from fixedhierarchy;
Which should return to select it:
'peter'|'A1'
'paul'|'A1'
'thomas'|'A1'
'thomas'|'C2'
'thomas'|'D3'
'heidi'|'G1'
'heidi'|'H2'

Hello

Thanks for posting the CREATE TABLE and INSERT statements; It's very useful! Don't forget to mention which version of Oracle you are using. This is especially important with the predetermined; all versions since Oracle 7 had significant improvements in how to handle them.

I'm kinda comfused about what you want. Are you trying to permanently change the tables? If so, show what the changed table should look like when the work is completed. After the release, you do not want to see of "SELECT * of useritems;" or "SELECT * FROM foohierarchy;", or, if you want to change the two tables, both.

Looks like you have two distinct problems:
(1) change foohierarchy, so that each item appears once as a child_id. That means add lines with NULL parent_item for all the roots ('A1', 'E1' and 'G1'). The query you posted seems oriented toward it.
(2) denormalization useritems, so that when a user name is bound to an element, the user name is linked to all this that the ancestors of the element, too. Results you posted seem to be what you want useritems to look after that.

Here's how to do these things:

(1) change of foohierarchy


The query you posted seems good. Do you see anything wrong with it? You can use this query (or something very close to it) in an INSERT or MERGE statement.
If you just want to add some new lines to foohierarchy, you need not Union: just the second part of it. If you are sure that none of these lines already exist in foohierarchy, then

INSERT INTO foohierarchy (parent_item,      child_item)
     SELECT DISTINCT   NULL,          childitem
     FROM     foohierarchy
     WHERE     parent_item     NOT IN (
                         SELECT      child_item
                         FROM     foohierarchy
                           )
;

If some of the roots may already exist in foohierarchy correctly, then you will like something in the WHERE clause to make sure that you n '; t add a duplicate. A MERGE statement can do better than the INSERT.

(2) useritems denormalization


This adds new lines at useritems, to make it look like what you have posted:

ERGE INTO     useritems     dst
USING (
     WITH     all_ancestors     AS
     (
          SELECT     CONNECT_BY_ROOT child_item     AS descendant
          ,     parent_item               AS ancestor
          FROM     foohierarchy
          START WITH     child_item   IN     (
                                   SELECT     item
                                   FROM     useritems
                              )
          CONNECT BY     child_item   = PRIOR parent_item
     )
     SELECT DISTINCT
          u.username
     ,     a.ancestor
     FROM     all_ancestors     a
     JOIN     useritems     u  ON     a.descendant     = u.item
      )                    src
ON     (     src.username     = dst.username
     AND     src.ancestor     = dst.item
     )
WHEN NOT MATCHED THEN
     INSERT     (dst.username,     dst.item)
     VALUES     (src.username,     src.ancestor)
;

After doing this, ' SELECT * from useritems; "will produce this output:

USERNAME   ITEM
---------- ----------
paul       A1
peter      A1
thomas     A1
thomas     C2
thomas     D3
heidi      G1
heidi      H2

Here's how it works:
All_ancestors of the subquery is a bottom-up CONNECT BY query, connecting each node in useritems with all his ancestors. CONNECT requests are often slow in the best of circumstances; do a join in a query CONNECT BY makes it even slower. It is more effective to CONNECT BY query first, in a subquery and then join tht game results at the other tables, like I did in src.

Tags: Database

Similar Questions

  • Send the application to the foreground start the system for 5 seconds...

    Hello everyone, I have an application that is run automatically at startup. I need the application stays on foreground for 5 seconds when the system boots. How can I do this? Help, please.

    Thank you...

    If this is resolved can mark you properly.  Help instructions in link above.

    If not, then given your needs, I would go with a comprehensive dialogue screen and a DialogCloseListener, that will kill your application if the answer is not correct.  .

  • Use the dynamic filter Condition in the mapping

    Hello

    I tried to use a dynamic filter condition in my correspondence.

    I wrote this condition as:

    INOUTGRP1. Numer1 = ' | Number 1 | '
    and INOUTGRP1. Number2 = ' | Number2 '

    Number1 and number2 are setting for mapping entry, now I want to use the input parameter for the Filter Condition.

    Can someone tell me how I can handle this?

    Thanks in advance.

    Greetings

    You used wrong input parameters.
    Rather a link an input parameter to the operator to filter, then you can insert it from list of attributes as long as the same way as other attributes of filter operator group

    Kind regards
    Oleg

  • try to install on the second computer. Already had two licenses, one for the office, one for the laptop. Now try to install the Office composition on laptop. Applications are coming up with buy it now and the start of the trial. Any ideas?

    try to install on the second computer. Already had two licenses, one for the office, one for the laptop. Now try to install the Office composition on laptop. Applications are coming up with buy it now and the start of the trial. Any ideas?

    Hello

    Please see the below help documents:

    Applications creative Cloud back in test mode after an update until 2015 for CC

    Solutions to connection errors, activation and connection with creative Cloud applications and Creative Suite

    Kind regards

    Sheena

  • The dynamic firewall application on the VPN Clients with ASA

    Hello

    I'll put up a Cisco ASA to complete the remote VPN client connections, but I want to assure you that the dynamic firewall is enabled on the client.

    I know it's possible with the VPN concentrator, but cannot see any documentation detailing that can be performed on an ASA.

    Anyone encountered this?

    Thank you

    James

    I believe you can use Group Policy settings to configure the firewall client.

    You can find more information about this feature in the migration to http://www.cisco.com/en/US/docs/security/asa/asa72/vpn3000_upgrade/upgrade/guide/migrate.htmlguide.

    Hope this helps.

    Andrea.

    Step 1 under Configuration > VPN > General > Group Policy Panel, select group policy in the table and

    Click on change. ASDM displays the Edit Group Policy dialog box.

    Step 2: click on the customer Firewall tab Figure 5-6 shows the firewall client options configured for this example:

    • Inherit-disabled (disabled)

    • The required Firewall Firewall setting

    • Type firewall Cisco Integrated Client Firewall

    Firewall policy-policy (CPP) pushed •

  • Error in Event Viewer: loading libraries of dynamic links customized for each application. The system administrator should review the list of libraries

    My system features, i7 thinkpad w540, 16 GB of ram and a 256 GB ssd. Using MSE as av with AMBM pro

    whenever I start my system, win 7 x 64, I get the following error in the event viewer:

    Custom dynamic link libraries are loaded for each application. The system administrator should review the list of libraries to ensure that they are linked to trusted applications.

    any help with this error?

    Atul

    Description: NVIDIA shim dll initialization

    Product: Shim NVIDIA D3D drivers
    Company: NVIDIA Corporationhttp://systemexplorer.net/file-database/file/nvinit-dll/33069751

    I would not be concerned by this driver.

  • Why my Apple Watch is constantly with the application of the workout and kill my battery

    Since the last Watch 2.0 update my watch is constantly showing the little running man at the top of the watch.  He seems to think that I work constantly and telling me I'm burning crazy amounts of calories (pretty sure he thinks that my train ride is me currently underway).  For not to mention my battery dies quickly.  I started the day at 630 with 100% of battery, the green light on my wrist has served all day and my battery is at 13%.  How can I fix this.  I have not matched the watch and combined with new, but that solves nothing.  Any help would be appreciated since my watch is basically useless at this point.

    Hi Steve

    Green rider icon indicates that your watch has currently underway training.

    You can currently get a workout paused in the application of the workout or a third-party (for example, Strava) fitness application.

    If you have used Strava or any other third-party application, you must put an end to the activity via this application on your watch (not on your iPhone).

  • When I start firefox browser display a erroe message containing the text "point_except_handler4_common of procedure not found entry into the dynamic link library msvcrt.dll" I use windows XP

    when I start firefox browser an erroe message appear that contain this text "the procedure entry point_except_handler4_common could not be located in the dynamic link library msvcrt.dll" I am using windows XP  in English
    

    This has happened

    Each time Firefox opened

    Is start mozila firefox

    This problem may be caused by a problem with the file c:\windows\system32\dwmapi.dll
    The dwmapi.dll file is a Vista file and must be present in Windows XP.

    See also [tiki - view_forum_thread.php? idforum = 1 & comments_parentId = 417674]

  • Order of generation of the signal with the command START/STOP (State Machine approach)

    Hello

    I met the problem with the realization of control (START/STOP) signal generation using state machine.

    There are 4 States in the computer status (see 4 screenshots below).

    The problem is when I click the button START, only a short series of generated pulses.

    What is the staff of task_in/task_out issue, which is not properly managed?

    Thanks in advance

    Pavel.

    Oh... you have defined with the mechanical switch action up to published... Right click and go to mechanical Action > latch when released. Do the same for your Start button.

    You took a second to read down hold value, because your writing acquisition takes on this subject for a long time, apparently.

    The stop button the Application, I did switch when set to released. It is set to the switch so that it can be used as a local variable in the Acquisition State stop as Idle.

    Here's more info on mechanical actions.

  • When I start my PC, and before you start I receive this message from InfoCenter.exe - Application error - the application is not initialate properly (0xc0000135).

    Original title: initialize 0xc0000135

    When I start my PC, and before you start I receive this message from InfoCenter.exe - Application error - the application is not initialate properly (0xc0000135). I just click OK and continue. Any problem? Is this necessary application?

    Walter Rodriguez

    E-mail address is removed from the privacy *.

    10/07/12

    14:57

    Hello

    1. do you receive this after you see Start button or entry?

    2 have you made any changes to the computer before the show?

     

    Method 1: Boot errors are fixed by the clean boot.

    Perform the clean boot and see if that helps.

    A clean boot to check if startup item or services to third-party application is causing this issue.

    Reference: How to solve a problem by performing a clean boot in Windows Vista or Windows 7:

    http://support.Microsoft.com/kb/929135

    Note: when you're done to diagnose, follow step 7 in the article to start on normal startup.

     

    Method 2: Some malware parody itself as InfoCenter.exe, especially when it is located in the folder c:\windows or c:\windows\system32.

    I suggest you make a system full scan just to be sure.

    Here is a link that will give you information on how to perform a full scan of the system:

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

    , Note 1: The Microsoft Safety Scanner ends 10 days after being downloaded. To restart a scan with the latest definitions of anti-malware, download and run the Microsoft Safety Scanner again.

    Note 2: The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.

  • wuauclt.exe... application error the instruction at 0x003c2713 referenced memory at 0x7074746b could not be read error whenever I start up system.

    Original title: wuauclt.exe... application error the instruction at 0x003c2713 referenced memory at 0x7074746b can not be read

    Hello

    Get this message every time I start starting System... I have XP and the system is fairly new... I happen to buy and download a new version of "Registry Mechanic"... and this question popped up a few days after I started using it... If safe to say... He must have done something.
    Anything goes wrong... always fast system, and no further questions, but who want to fix the error... of what I can take. Please notify :-)
    Thank you!
    Mark

    Hello

    Step 1: Perform the clean boot on the computer.

    From your computer by using a minimal set of drivers and startup programs so that you can determine if a background program is interfering with your game or program. This type of boot is known as a "clean boot".

    Reference:
    How to configure Windows XP to start in a "clean boot" State
    http://support.Microsoft.com/kb/310353

    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:
    1. click on Startand then click run.
    2. type msconfigand click OK.

    The System Configuration Utility dialog box appears.

    3. click on the general tab, click Normal startup - load all services and device drivers and then click OK.
    4. When prompted, click on restart to restart the computer.

    Step 2: Perform SFC (System File Checker) scan on the computer.

    SFC tool scans system files and replaces incorrect versions of system files by using the correct versions.

    1. open an administrator command prompt. To do this, click Start, click principally made programs, Accessories, right-click guest, and then click run as administrator.

    If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.

    2. at the command prompt, type the following line and press ENTER:
    sfc/scannow

    Reference: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/system_file_checker.mspx?mfr=true

  • Starting problems. - RunDLL32.exe, procedure entry point_except_handler4_common could not be located in the dynamic link librarymsvcrt.dll

    I get the message RunDLL32.exe, procedure entry point_except_handler4_common could not be located in the dynamic link librarymsvcrt.dll. What should I do?

    I had starting problems, boot loop, I think it seems to have been resolved by using the last known good configuration, but I get this popup dialog box. I've not closed for fear that it will start XP looping again.

    Hi EddieBryan,

    1. did you of recent changes on the computer?

    2. do you have security software installed on the computer?

    3. when exactly you receive the error message?

    Method 1
    Check if the problem persists in safe mode and after return with the result.
    A description of the options to start in Windows XP Mode
    http://support.Microsoft.com/kb/315222

    Method 2
    If the problem does not persist in safe mode, then it is possible that some third-party programs installed on the computer is causing the problem.
    I suggest that you configure the computer in a clean boot state and check if it helps.
    To help resolve the error and other messages, you can start Windows XP by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.
    See section to learn more about how to clean boot.
    How to configure Windows XP to start in a "clean boot" State
    http://support.Microsoft.com/kb/310353

    Reset the computer to start as usual
    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:
    1. click on Start , then click run.
    2. type msconfig , then click OK.
    The System Configuration Utility dialog box appears.
    3. click on the general tab, click Normal Startup - load all services and device drivers and then click OK.
    4. When prompted, click on restart to restart the computer.

    Method 3

    If the previous step fails then I suggest that scan you SFC on the computer that will search the corrupted system files and try to correct them.

    The analysis may take some time, so be patient. Windows allows to fix corrupt or missing files it finds. If the information of the installation CD is required to fix the problem, you may be asked to insert your Windows XP installation CD.

    Description of Windows XP and Windows Server 2003 System File Checker (Sfc.exe)

    http://support.Microsoft.com/kb/310747

    You are prompted to insert a Windows XP SP2 CD when you try to run the tool on a Windows XP SP2 computer system File Checker

    http://support.Microsoft.com/kb/900910

  • computer will not start up - the application or the C:\WINDOWS\system32\DNSAPI.dll DLL is not a valid Windows image

    When I try to start my computer, I get this message... [the application or the 32DNSAP.dll DLLC:windows\system is not a valid image. [Please check this against your installation diskette.]  However, after inserting disc and reboot, I get the same message, and the computer starts. Any suggestions? Please and thank you

    Well, I know what this means and have recreated on my system (that's how I got the exact message).

    Now we will see this as the system engineers of Microsoft came up with a workable solution that does not involve the possession of a genuine bootable XP installation CD (sorry - there is no Microsoft KB article for this message).

    MS has a free support that might be useful:

    http://support.Microsoft.com/kb/2509553

  • Double-click Application warning "the file has not a progress associated with it for performing this action.

    By double clicking or open an application the following message window appears:

    "This file has no program associated with it for performing this action.  Create and link in the set Associations control panel. »

    I can launch the application (like Word or Internet Explorer) by right clicking on the executable and selecting the option 'start '.

    Because these files are the application files, I'm not aware of a method to create an association for it.  I thought it was for files that must be associated with an executable file. "as a Word to Word document".

    How can I solve this problem?

    Thank you

    How to set file Associations:

    http://articles.TechRepublic.com.com/5100-10878_11-6172036.html

    How do I... Change file extension associations in Windows Vista?

    See you soon.

    Mick Murphy - Microsoft partner

  • Application to the/debug context - portal of path could not be started

    Hello community,

    I downloaded and installed the SDK of Service Push BlackBerry v1.0.0.5 assisted by the Getting Started Guide.

    I am able to start the Tomcat service and also confirm it works by visiting https://localhost:8443 / (where I see the Apache welcome screen), but I get an HTTP 404 status message when I try to open the default applications https://localhost:8443 / debug-Portal /, https://localhost:8443 / sample-app / and https://localhost:8443 / pushsdk /.

    On the Tomcat Web Application Manager applications are closed.

    While trying to start these applications, I get the following error messages:

    FAIL - Application to the/debug context - portal of path could not be started
    FAIL - Application to the context/sample-app path could not be started
    FAIL - Application to the context path /pushsdk could not be started

    My knowledge of Tomcat and Java is practically zero...

    Hope someone is able to help me with this problem.

    Installed:

    Apache-tomcat - 6.0.20

    -Windows XP + SP3

    I found the cause of my problem.

    I forgot to put the ID of the application during Installation.

Maybe you are looking for

  • How to keep passwords to be deleted after disconnection of the Firefox Sync?

    Recently reinstalled Windows and Sync used to migrate all data. After disconnecting the synchronization, all saved passwords have been removed. Is it possible to keep them without being connected to Sync?

  • Equium A100-147 would not start

    Equium A100-147 would not start. Only the lights next to the CapsLock F10 F11 keys are on. When the switch is pushed the lights disappear back only after about 15 seconds. Help, please.

  • Frightening images of LabVIEW

    They gave me WCC developed by others, to establish and support. While that clean error clusters I have started running acroos the 'manifest error' VI used TOO many places I've done a quick serach to see how extensive and got this. I'll have to take a

  • PXI-8186 is not to ping requests

    I apologize in advance because I'm rather new to LabVIEW and PXI hardware. I have a NI PXI-8186 controller who all of a sudden can be reached via the network. The PC is connected to the controller via a hub.  I was able to ping another device also on

  • set up a second screen with dvi with a hpp7 port 1054

    I have a hp pavllion p7-1054 and I am trying to hang a second monitor to the dvi computer port does not recognize the monitor