Find the Agent and their Manager - connect by

Hello
version database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please help me to know Agent and their Manager. also published the desired output
CREATE TABLE AGENT
(
  AGENT_NAME  VARCHAR2(100 BYTE),
  SID         NUMBER,
  MGR1        VARCHAR2(100 BYTE),
  MGR2        VARCHAR2(100 BYTE),
  DEPT_ID     NUMBER,
  START_DT    DATE,
  END_DT      DATE
);

CREATE TABLE PERSON
(
  PERSON_NAME  VARCHAR2(100 BYTE),
  SID          NUMBER,
  DEPT_ID      NUMBER,
  START_DT     DATE,
  END_DT       DATE
);

SET DEFINE OFF;
Insert into PERSON
   (PERSON_NAME, SID, DEPT_ID, START_DT, END_DT)
 Values
   ('DEEPAK', 200, NULL, NULL, NULL);
Insert into PERSON
   (PERSON_NAME, SID, DEPT_ID, START_DT, END_DT)
 Values
   ('VIJAY', 300, NULL, NULL, NULL);
Insert into PERSON
   (PERSON_NAME, SID, DEPT_ID, START_DT, END_DT)
 Values
   ('MICHELLE', 400, NULL, NULL, NULL);
Insert into PERSON
   (PERSON_NAME, SID, DEPT_ID, START_DT, END_DT)
 Values
   ('NATLO', 500, NULL, NULL, NULL);
COMMIT;


SET DEFINE OFF;
Insert into AGENT
   (AGENT_NAME, SID, MGR1, MGR2, DEPT_ID, 
    START_DT, END_DT)
 Values
   ('AGENT4', 103, 'NATLO', 'MISHKA', NULL, 
    NULL, NULL);
Insert into AGENT
   (AGENT_NAME, SID, MGR1, MGR2, DEPT_ID, 
    START_DT, END_DT)
 Values
   ('AGENT1', 100, 'DEEPAK', 'MICHELLE', 10, 
    TO_DATE('01/01/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AGENT
   (AGENT_NAME, SID, MGR1, MGR2, DEPT_ID, 
    START_DT, END_DT)
 Values
   ('AGENT2', 101, 'MICHELLE', 'VIJAY', 55, 
    TO_DATE('01/01/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('05/01/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AGENT
   (AGENT_NAME, SID, MGR1, MGR2, DEPT_ID, 
    START_DT, END_DT)
 Values
   ('AGENT3', 102, 'VIJAY', 'NATLO', 105, 
    TO_DATE('05/12/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('12/31/9999 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
output Required:
Agent1  100 DEEPAK MICHELLE VIJAY NATLO MISHKA
Agent2  101 MICHELLE VIJAY NATLO MISHKA
Agent3  102 VIJAY NATLO MISHKA
Agent4  103 NATLO MISHKA

Hello

You can simplify the solution Al's using pseudo-column CONNECT_BY_ISLEAF:

SELECT    CONNECT_BY_ROOT(agent_name) agent_name
        , CONNECT_BY_ROOT(sid) sid
        , SYS_CONNECT_BY_PATH(mgr1,' ')||' '||mgr2 path
--      , ROW_NUMBER() is not needed
     FROM  agent
     WHERE CONNECT_BY_ISLEAF     = 1     -- *****  Added  *****
  CONNECT BY PRIOR mgr2 = mgr1
;

In addition, mixture of analytical functions and CONNECT BY in the same query does not always. Before Oracle 11.2, it almost never works. I have not seen documentation on this, but I am always wary. In any case, CONNECT_BY_ISLEAF is simpler and more efficient, if you want even use ROW_NUMBER here.

Remember that Oracle 11.2 has recursive WITH clauses, which can do everything that CONNECT AT the time, and much more. For this particular problem, CONNECT BY is always the best solution, but don't forget that you now have a choice.

Tags: Database

Similar Questions

  • In photoshop CS5 (bridge) I could select all the images and their size still before turning them into JPEG files. I can't find a way to do it in CC

    In photoshop CS5 (bridge) I could select all the images and their size still before turning them into JPEG files. I can't find a way to do it in CC

    Hi Tanuj.

    I actually understand it. Not the best user friendly system. Where as before (CS5), I just had to go to crop tool and choose the dimensions and the inches now it in the window. Just really complicated for nothing.

    Thanks anyway Tanuj

    Melanie

  • I went to the suppliers and lost my connection to get my computer also work like a TV.

    I went to the suppliers and lost my connection to get my computer also work like a TV. gives me the error that I have no configured TV tuner card to work with windows media center. He is told to go into the settings of the TV & set up your TV signal, but I don't know where it is. Please help me.

    Hi Lisa,
    Click Start, click Control Panel

    Click the Hardware tab, and then click Device Manager.

    Right click on the device, and then click Properties.

    Click on the driver tab, then click on set to update driver.

    Follow the instructions on the screen to complete the update of the driver.

    b Eddie

  • Error in Windows Mail - "error 623 - system could not find the directory entry for this connection".

    Original title: Windows Vista, Windows Mail, error 623, unable to connect to the mail.
    This problem occurred after a storm. Modem was fried.  Replaced the modem with the modem "2wire" ATT.

    Now get "error 623: the system could not find the directory entry for this connection"or the sys works very well. " Att think maybe in Vista?  Help, please. Works of g-mail, but I like Windows mail.

    Hello Bbuddes,

    You can watch the following information/tutorial to help with most of the problems of Windows Mail.
    http://www.Vistax64.com/tutorials/62560-Windows-Mail-problems.html

    There is a section to reset Windows Mail which can help with your problem.

    Sincerely,.

    Marilyn
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think

  • Query to find the Pages and the list of permissions associated with a particular role in PS

    I want a query to find the Pages and the list of permissions associated with specific roles in PS.

    For example, if we see the role of manager accounts payable, it conatins Pages and the list of permissions.

    But, to get everything in EXCEL sheet by Manuel priocess's BIG job. So, can someone give me the query.

    Please try under queries

    The roles assigned to the list of Perm:

    SELECT B.ROLENAME

    OF PSCLASSDEFN A, PSROLECLASS B

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1).

    List of Perm pages can access:

    SELECT B.MENUNAME, B.BARNAME, B.BARITEMNAME, B.PNLITEMNAME, C.PAGEACCESSDESCR, B.DISPLAYONLY

    OF PSCLASSDEFN A, PSAUTHITEM B, PSPGEACCESSDESC C

    WHERE (A.CLASSID = B.CLASSID

    AND A.CLASSID =: 1

    AND B.BARITEMNAME > ' '

    AND B.AUTHORIZEDACTIONS = C.AUTHORIZEDACTIONS)

  • How can I start the BI and ODI Managed Servers?

    Well,.

    I read at step 4 of Doc-ID 1589540.1 the following:

    "BI applications requires the BI and the ODI Managed Servers (bi_server1 and odi_server1) should be started via the node Manager. This setting is required for settings, memory, and jvm arguments are correctly defined.

    Starting not not the BI and managed servers of ODI can lead to memory problems and the loss of functionality BI Applications Configuration Manager, the Manager of functional installation and ODI.

    To ensure that the BI and ODI Managed Servers are started through the node Manager, start using the Console of Administration WebLogic user interface.  Do not start the BI and servers managed by ODI by using the managed server start script. »

    Well, as I'm new Weblogic management, then, what are the steps to start all of the services?  (I have OBIEE, ODI and Bi Apps on the same server).

    I mean, was that you should not start their script. What is the proper sequence and how should I do this?

    Could someone help me on this?

    Thanks in advance...

    the appearance of the home screen for environment-> servers-> here you will see the admin and managed servers-> click the tab control and then check off the boxes related to managed servers, and then click start that's all

  • My iPAD asks me to update to OS 9.3, but the update fails because it says that the iPAD is not connected to the internet and when I connect to my computer iTunes it say my OS is up to date.  Help, please.

    My iPAD asks me to update to OS 9.3, but the update fails because it says that the iPAD is not connected to the internet and when I connect to my computer iTunes it say my OS is up to date.  Help, please.

    I'm surprised to hear that for an iPad 2 that the issue had apparently been set for 2 s. Please see this for more details as I know them. Maybe the servers at your site have not been updated yet for the new version of the iPad 2.  ???

    Apple released the update iOS 9.3 for older devices (air of iPad and previous iPhone, 5 s and previous) due to problems with Activation. See the following for details and possible solutions.

    http://www.IMore.com/Apple-working-iOS-93-fix-older-iPhone-iPad

    https://support.Apple.com/en-us/HT206203

    A new version for the iPad 2 is now available which does not require the activation step. A new version for other devices is not yet available.

  • Toshiba 40TL938G - find the date and time settings

    I have a 40TL938G and I can't find the date and time settings.
    Can someone help me?

    SSY
    I read the manual and it does ' t say anything about these settings.

    THX

    In the settings of digital television, you should see the option called local time settings

    To display the time on the TV you press the sign of the small clock on the remote control while watching a normal TV show (analog only)

  • Find the Center and angle

    Hello. I have two markers. It is stationary and the other is moving (app.jpg). How can I find the centers and angles shown in picture (app.jpg)?


  • How to find the utilities and windows drivers VGN-CR36G 8?

    Hello

    I use laptop Vaio VGN-CR36G with vista ultimate. Now, I want to install windows 8 enterprise edition.

    But I can't find the drivers and utilities on the site of sony vaio.

    But my product is compatible for windows 8 OS.

    Here is the link below:

    http://www.Sony-Asia.com/support/product/VGN-CR36G

    Can someone please help me to download all drivers and software?

    Thank you

    Hi Whiteeasy.

    This model does not support Windows 8 operating system which you can confirm from the link below.

    http://www.Sony-Asia.com/microsite/VAIO/support/GetWindows8/GetWindows8_EN_NA.html?referer=http%3A%2...

    If my post answered your question, please mark it as an "accepted Solution".

  • How to find the Maxima and Minima for each column of a 2D array?

    Hello

    I have a 2D chart and I would find the maxima and minima of each column of the 2-D table. Even though I know how to get maxima and minima for the whole picture but don't know how columnwise? Any ideas please?

    Thank you

    Rohit

    Hello

    @Smercurio-What you said is true, I should have shown using automatic indexing enabled which is really excellent choice. I just tried to show in a very simple way.

    Anyway, here's the best way

  • How to find the maximum and minimum of a waveform between cursors

    Hello!

    Does anyone know an easy way to find the maximum and minimum of a waveform between two sliders?

    Kind regards

    Andreas

    Hi Andreas,

    attached, you get an example of it in MeasurementStudio.

  • Cocomputer cannot find the printer and I do not have a disk for it

    Original title: printer SUPPORT

    my computer cannot find the printer and I do not have a disk for it

    Then, download and install the appropriate drivers on the printer manufacturer's support web site.

  • When I try to open the keyboard screen, I get the prompt and click to connect, but it does not connect.

    OT: On the keyboard interface.

    When I try to open the keyboard screen, I get the prompt and click to connect, but it does not connect. My hard keyboard is dysfunctional and now I can't type my password to connect. Is there a way to get around this? Thanks for any help.

    There is a problem with the KB3004394 update that causes what you see as well as other issues.

    Uninstall this update, your system should return to normal.

    While in Windows Update, select View Update History then installed updates. Go to the bottom of the list to KB3004394, right-click on it and choose uninstall.

    Microsoft has removed the update of the distribution.

    I would try to borrow a keyboard if you can so that you can perform the uninstall.

  • I have a U135 DX netbook with a built-in webcam. How can I find the cam and I press these keys for easy access

    I have a U135 DX netbook with a built-in webcam. How can I find the cam and I press those keys for easier access please PS I'm not a manual.

    You can get a manual here.

    http://www.msi.com/product/NB/U135DX.HTML#/?DIV=manual

Maybe you are looking for