Help regarding CONNECT BY PRIOR AND LEVEL
Hi
I need to retreive all the employees that are at the least level under a particular employee. Assume basic emp table.
I have been using CONNECT BY PRIOR
select mgr,empno,ename, level from emp
start with empno=7839
connect by prior empno=mgrOUTPUT:
MGR EMPNO ENAME LEVEL
7839 KING 1
7839 7566 JONES 2
7566 7788 SCOTT 3
7788 7876 ADAMS 4
7566 7902 FORD 3
7902 7369 SMITH 4
7839 7698 BLAKE 2
7698 7499 ALLEN 3
7698 7521 WARD 3
7698 7654 MARTIN 3
7698 7844 TURNER 3
7698 7900 JAMES 3
7839 7782 CLARK 2
7782 7934 MILLER 3The Output i require should be
MGR EMPNO ENAME LEVEL
7788 7876 ADAMS 4
7902 7369 SMITH 4
7698 7499 ALLEN 3
7698 7521 WARD 3
7698 7654 MARTIN 3
7698 7844 TURNER 3
7698 7900 JAMES 3
7782 7934 MILLER 3Also if i change the empno then i need to get only the employees under that employee only.
Thanks in Advance,
G.Vamsi Krishna
oracle_for_dude wrote:
can you explain what is this query doing
SQL> select mgr,empno,ename, level
2 from emp
3 where level > 2
4 start with empno = 7566
5 connect by prior empno = mgr;
MGR EMPNO ENAME LEVEL
7788 7876 ADAMS 3
7902 7369 SMITH 37566 in scott.emp table is employee_id of JONES, It's displaying the selected columns for all the employees in the sub-tree starting with Jones, not including Jones (who is at LEVEL=1) and the people who report directly to Jones (LEVEL=2).
>
>
Thanks in advance
Similar Messages
-
CONNECT BY PRIOR and performance of Query Plan
Anyone,
I have an SQL Statement that is performing rather slow and I am trying to figure out if I could optimize it. Here is the SQL:
SELECT/*+ index(MAXIMO.EQNDX99) */
maximo.equipment.eqnum, maximo.equipment.parent, LEVEL
FROM maximo.equipment@maxi_dblink
WHERE parent = :b1 CONNECT BY PRIOR eqnum = parent
ORDER BY eqnum, LEVELAfter some research in this board I followed some advice found to create an index on the table for both the eqnum, parent and the parent, eqnum. EQNDX99 and EQNDX999 respectivley.
Now the Qery Plan for this query shows the following:
SELECT STATEMENT (REMOTE)
SORT (ORDER BY)
FILTER
CONNECT BY
INDEX (FAST FULL SCAN) EQNDX99 (NON-UNIQUE)
TABLE ACESS (BY USER ROWID) EQUIPMENT
INDEX (RANGE SCAN) EQNDX999 (NON-UNIQUE)Now it appears to be using both indexes but it is operating through a DBLINK. Is there anything else I can do to increase performance??? It appears to be using the HINT through the link as well.
Thanks for any help I can get,
David Millerhow long does it takes to complete the query?
-
Help with 'connect by prior' statement
I've got a quoting report that is sporadically ordering incorrectly and I've traced the source down to a 'connect by prior' statement. Can I get an explanation of what the statement is doing so I can figure out how to change it to get the desired results?
select rownum config_rownum, quote_line_id,related_quote_line_id rlid, level
from aso_line_relationships
where relationship_type_code = 'CONFIG'
connect by prior related_quote_line_id = quote_line_idsample output for the line_ids for one quote:
CONFIG_ROWNUM QUOTE_LINE_ID RLID LEVEL
1 7438 7439 2
2 7440 7441 2
3 7430 7431 2
4 7432 7433 2
5 7432 7434 2
6 7432 7435 2
7 7436 7437 2
8 7442 7443 2
9 7442 7444 2
10 7442 7445 2
11 7442 7446 2
12 7442 7447 2
13 7442 7448 2
14 7442 7449 2
15 7450 7451 2
16 7452 7453 2
17 7452 7454 2
18 7452 7455 2
19 7456 7457 2
20 7456 7458 2
21 7456 7459 2
22 7460 7461 2
23 7460 7462 2
24 7463 7464 2
25 7430 7431 1
26 7432 7433 1
27 7432 7434 1
28 7432 7435 1
29 7436 7437 1
30 7438 7439 1
31 7440 7441 1
32 7442 7443 1
33 7442 7444 1
34 7442 7445 1
35 7442 7446 1
36 7442 7447 1
37 7442 7448 1
38 7442 7449 1
39 7450 7451 1
40 7452 7453 1
41 7452 7454 1
42 7452 7455 1
43 7456 7457 1
44 7456 7458 1
45 7456 7459 1
46 7460 7461 1
47 7460 7462 1
48 7463 7464 1 The correct ordering can be seen by running this statement:
select rownum config_rownum, quote_line_id,related_quote_line_id rlid
from aso_line_relationships
where relationship_type_code = 'CONFIG' and quote_line_id between 7430 and 7464
CONFIG_ROWNUM QUOTE_LINE_ID RLID
1 7430 7431
2 7432 7433
3 7432 7434
4 7432 7435
5 7436 7437
6 7438 7439
7 7440 7441
8 7442 7443
9 7442 7444
10 7442 7445
11 7442 7446
12 7442 7447
13 7442 7448
14 7442 7449
15 7450 7451
16 7452 7453
17 7452 7454
18 7452 7455
19 7456 7457
20 7456 7458
21 7456 7459
22 7460 7461
23 7460 7462
24 7463 7464I tried to substitute the simple query above for the 'connect by prior' query in the report but failed because something in the report is expecting input from the 'connect by prior' statement. So eliminating the statement is not a choice."connect by prior " is for for hierarchical queries which is for data has parent-children relationship, and ususlly its' result is used to populate tree-like data result. and order by is NOT recommend since it will destroy the hierarchical order.
you could use "order by sibiling" if you would like to order inside the same level of data -
I know how to change my network settings to fix my internet connection, I just select "Auto-detect network settings for this network" under Tools, Options, Network, Settings. However every time I close down Firefox it reverts to the manual proxy configuration pointing to 127.0.0.1 Port 55414.
I've tried all the suggestions under saving your preferences but this hasn't worked so I'm at a loss as to what to do next. If I can't sort this I'll have to revert back to Internet Explorer as this doesn't have this problem!I know how to change my network settings to fix my internet connection, I just select "Auto-detect network settings for this network" under Tools, Options, Network, Settings. However every time I close down Firefox it reverts to the manual proxy configuration pointing to 127.0.0.1 Port 55414.
I've tried all the suggestions under saving your preferences but this hasn't worked so I'm at a loss as to what to do next. If I can't sort this I'll have to revert back to Internet Explorer as this doesn't have this problem! -
Need help regarding Simple Data Client and Simple Data Server VIs
Hi everyone.
I have a simple objective. I just want to test the 2 example VIs, "Simple Data Client" and "Simple Data Server" between 2 computers. I just want to check whether is this working between the 2 computers.
What I have done for now is that I changed the "address", from "localhost" in the "Simple Data Client.vi" to the IP address of the computer running the "Simple Data Server". I runned the "Simple Data Server" VI in one of the computers first followed by the "Simple Data Client" in the other computer. Nothing is received and the client just timed out.
Can anyone please help me troubleshoot and tell me what are the possible problems for this? Are there any wires connections between 2 computers that I am missing or any other configurations I have to make before I can successfully do this?
Thanks.
Regards,
JonathanHi Lee.P.
I understand that. I was just feeling frustrated about the project not working. Sincere apologies from me.
I was wrong about the error number. It is not Error 60. It is Error 59 - The network is down, unreachable, or has been reset.. Yes, I have tried changing the port numbers at the 2 computers when trying to send/receive.
Could anything else be the problem?
Regards,
Jonathan -
Need help regarding Apache httpd.conf and PHP setup.
Hi,
I am facing problem setting up my PHP and apache setup. I have installed Apache2.2 Root path = C:\Program Files\Apache Software Foundation\Apache2.2
I have also installed PHP in my C:\PHP drive earlier. I moved this PHP folder to C:\Program Files\Apache Software Foundation\Apache2.2 just to keep all things at one place.
I have copied php5ts.dll at 4 locations - C:\Program Files\Apache Group\Apache2 \bin , %SYSTEMROOT%\System32, %SYSTEMROOT%\system and %SYSTEMROOT%. I have also added these paths in Environment variable 'PATH'.
In httpd.conf file entries are as follows:
ServerRoot "C:/Program Files/Apache Software Foundation/Apache2.2"
I have added these 3 lines as
LoadModule php5_module php/php5apache2.dll
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
When restarting apache http server I get message as:
httpd.exe error ...... cannot load C:\Program Files\Apache Software Foundation\Apache2.2\php\php5ts.dll into the server. The specified module could not be found.
I have checked that php5ts.dll DLL exist at above path. Please help me out urgently.Sorry I don't have Windows available to check the paths. With recent versions
of PHP I never copied files out of the php source directory.
Make sure the Oracle 10g Instant Client is in your PATH environment variable.
You could try using the PHP Windows MSI installer.
cj -
In urgent need of help regarding getting month name and dates
Hi Experts
I have a table called MONTHLYBILL with Column TRANSACTIONMONTH. I need one query / function / SP to do return ouput based on following combination. I am using Oracle 9i
Have researched on various forums, documents but unable to get the desired output. Finally here in hope of help.
Input
From Date: 06/01/2011
To Date: 12/03/2011
Output
Month: DECEMBER-2010 (previous month of From Date). Now if DECEMBER-2010 is not available in table, then returns the
month which is available immediately the month preceeding DECEMBER-2010
Begin Date: 01/01/2011 (1st day following the month returned in output)
End Date: 31/03/2011 (last date of month based on input To Date)
Input
From Date: Null
To Date: 12/03/2011
Output
Month: First available transactionmonth in DB (say JANUARY-2010)
Begin Date: 01/02/2011 (1st day following the month returned in output)
End Date: 31/03/2011 (last date of month based on input To Date)
Input
From Date: Null
To Date: Null
Output
Month: First available transactionmonth in DB (say JANUARY-2010)
Begin Date: 01/02/2011 (1st day following the month returned in output)
End Date: Current month's last dateWhat is your application release?
I am in big trouble now.. can anyone help....
I have a backup of an EBS instance, lets say it was taken one month ago, and now we got some datas lost in the current production server..
some one deleted some datas...
Now we need some specific data from the old backup and restore it to the production
or can it be restored? please help me guys...What kind of data? What is the table name?
Since this is a production issue, I would suggest you log a SR.
Thanks,
Hussein -
Need some help regarding Client Proxy generation and test via SOAMANAGER
Hello,
we are integrating a 3rd party Java client via webservices.
For that matter I generated a client proxy (consumer proxy) in se80 using the existing WSDL.
This worked fine.
The I wanted to create a logical port.
Since this is only possible in SOAMANAGER I tried it there.
Trying to do this automatically by the given WSDL file didn't work. The system dumps.
So, I tried the manual approach by entering the server name and path in the 'Transport settings' tab.
Now I wanted to test this.
Unfortunately the test function in se80 (Proxy->Test) doesn't show a positive result.
I always get an error
SOAP:1.023 SRT: Processing error in Internet Communication Framework: ("ICF Error when receiving the response:
ICM_HTTP_CONNECTION_FAILED")
So, I am kind of stuck here.
Do you guys have any idea what's wrong (approach, settings, bugs)?.
I tested the webservices with a test application (soapUI), and they work fine.
So it seems to be a problem in the proxy framework or a network problem?
I really appreciate any kind of help.
Thanks,
Michaeli created the port in soamanager.Do i need to create in lpconfig also?
yes i have loaded the certificate in strust.
i am getting the response also from the web service. as Security requirements are not satisfied because the security header is not present in the incoming message.
i need to pass the user name and password while using the method.wsse security.wld u have any clue? -
I have an issue with my ipad2. There is a dialogue box open stating "Cannot verify server identity - Hotmail can't verify the identity of "m.hotmail.com" - Would you like to continue anyway?" I cannot close it close this box no matter what I press. As a result I cant get in to my ipad. Any ideas on what I can do? I have tried switching it off but this doesn't work either.
You need to force quit whatever is happening to you. Try a reset, reboot. Hold the home and sleep button until the apple logo appears. Ignore the red slider.
What may be happening is that the set up for your hot mail account is wrong or has failed, and if you have push or fetch turned on, one of the first things the pad will do is to establish contact, and check your mail. If it cannot get through because of the set up, it comes to a stop, wanting you to fix that problem.
If you have a wifi only, try to start up the pad where there is no signal. And if your have 3 g, turn it off. You want the pad to thing there is no signal, so dont try to look for the mail.
What happens if you push home from that screen? It should goto the home page. Then go immediately to settings, mail, and either fix the setting, or delete the account and start over. But turn off push or fetch until you get it sorted out. -
Connect by prior usage restricted to certain level in an hierarchy.
Hi,
I had a requirement where the values are stored in a hierarchial basis in a database table. The hierarchy is upto five levels. When I use connect by prior, its using all the five levels to evaluate. But I want to restrict the evaluation upto only three levels. So can anyone help me out in resolving the issue. I would like to know how we restrict, the usage to only say, two or three levels.
Any help is highly appreciated.
Thanks and Regards,
Venky.Just add AND LEVEL < 4 to CONNECT BY clause. For example:
SQL> select lpad(' ',(level-1)*2) || level || ' ' || ename as ename
2 from emp
3 start with mgr is null
4 connect by prior empno = mgr
5 and level < 4;
ENAME
1 KING
2 JONES
3 SCOTT
3 FORD
2 BLAKE
3 ALLEN
3 WARD
3 MARTIN
3 TURNER
3 JAMES
2 CLARK
ENAME
3 MILLER
12 rows selected.
SQL> SY. -
'CONNECT BY PRIOR..START WITH' clause Usage
Hi All,
Could you please let me know the usage of 'connect by prior...start with' clause.
I only know that it helps for hierarchial retrival,but not aware of details.
Can someone provide the use with example for the same.
On searching on the net,I have seen numerous examples but none of them could explain it properly and everywhere the same SCOTT/TIGER schemas EMP and MGR table's example is given which is not enough explanatory.
Thanks in advance...
Aashish S.suppose u need to get all employees in a company in a hirerchical manner
ie presdent then mgrs
then employeess reporting to them
this can be done using connect by prior and start by
select empname from emp
connect by prior empno=mgrno
start with mgrno is null -
Help Regarding Xi integrating with Seibel System.
HI @,
I have to intergrate a seible system with R/3 but I haven't worked on the same before.
I need help regarding seibel inetrgartion scenarions and various adapters that can be used in that conditions.
Documents on Seible Integration will b really helpful.
RegardsIt would be better to go for the iway adapter for this integration requirement. The other documents can be obtained direclty from iway
Regards,
Prateek -
Hi
I have a table in Oracle which is a recursive (pigs ear) hierarchy. I want to be able to use this in disco and "wander" down the hierarchies using connect by prior and start with. Can this be done?Not sure if you're referring to a specific table.
However, I have create a report in the past that simply pointed to a database view we created that used the connect by idea and all worked well.
So, if you have a database view that returns what you're needing then no problem. -
Using START WITH and CONNECT BY PRIOR in a report
Hi - I am using Oracle 9i and reports 10g. Does anyone know of a reason why running my sql in TOAD will produce the correct results, but the report is dropping records? I am using start with and connect by prior to build a hierarchy of linked records. The report is dropping the "child records" and only returning records from the route level.
Thanks you for your help.Hi user574499
Could u pls share us ur Query...?
Regards,
Abdetu... -
Help me in understand connect By Prior
Hi ,
please help me in understand connect By Prior
I did a sample example , but unale to follow , please explain
How did it understand that KING shuld be displaed first .
On wht basis the results are shown here ?
SELECT empno,
ename,
job,
mgr,
hiredate,
level
FROM emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr
7839 KING PRESIDENT 17-Nov-81 1
7566 JONES MANAGER 7839 2-Apr-81 2
7788 SCOTT ANALYST 7566 19-Apr-87 3
7876 ADAMS CLERK 7788 23-May-87 4
7902 FORD ANALYST 7566 3-Dec-81 3
7369 SMITH CLERK 7902 17-Dec-80 4
7698 BLAKE MANAGER 7839 1-May-81 2
7499 ALLEN SALESMAN 7698 20-Feb-81 3
7521 WARD SALESMAN 7698 22-Feb-81 3
7654 MARTIN SALESMAN 7698 28-Sep-81 3
7844 TURNER SALESMAN 7698 8-Sep-81 3
7900 JAMES CLERK 7698 3-Dec-81 3
7782 CLARK MANAGER 7839 9-Jun-81 2
7934 MILLER CLERK 7782 23-Jan-82 3Hi,
user10503747 wrote:
Hi ,
please help me in understand connect By Prior
I did a sample example , but unale to follow , please explain
How did it understand that KING shuld be displaed first .
On wht basis the results are shown here ?In a CONNECT BY query (without an ORDER BY clause), if x is an ancestor of y (that is, if x is the parent of y, or x is the parent of the parent of y, and so on), then y will be displayed after x, but before any other row that does not have x as its ancestor. (That is also the order in which ROWNUM will be assigned. This applies only to the query in which CONNECT BY is done. If you use the results set as a sub-query, the super query may cause the results to be re-arranged. An ORDER BY clause always takes precedence.)
In a CONNECT BY query, every row in the result set either:
(a) satisfies the START WITH condition, or
(b) is a descendant of some row in (a); that is, some row that satifies the START WITH condition is its ancestor.
Since ancestors always come before their descendants, the first row in the result set must be a row that satisfied the START WITH condition. In your example, the row with ename='KING' was the only row that satisfied the condition "START WITH mgr IS NULL", and all the other rows are its descendants, so the row with ename='KING' must come first, as APC said.
Maybe you are looking for
-
What is the diff b/w Sap Scripts and Smart Forms
Hi, Whats the diff b/w SAP Scripts and Smart Forms.. I need the internal explanation for both Smart Forms and SAP Scripts mean when we execute what happens whether Print Program r Forms starts execution 1st and SIMILARLY FOR SMARTFORM
-
Can't Connect To WPA-PSK/AES
I've read through dozens of posts here and on other sites, but still can't figure this out. At home, I have a D-Link DI-634M wireless router. We have two laptops (Toshiba and IBM) that connect to it just fine, but I can't get my new iPhone 3G to conn
-
Hi need a help. I am trying to send PO created in me21n (service PO) to XI but not able to. i cud send orders02 by we19. i have configured output type n evrything. still stuck up. errs 1. no communication meduim defined for medium A:: whereas in nace
-
Is the 10.7.2 fixed battery drain problem ?
there is no information anywhere and I wonder if this problem is fixed ?
-
Eternal beach ball after 10.8.5 Combo Update
Just installed the 10.8.5 combo update on my mac mini (2013, i7). Everything was, of course, working perfectly with 10.8.4 Now I get the eternal spinning beach ball just before the login. I've already verified the boot hard drive, repaired permission