Connect by - no start Query
Is it possible to get the hierarchy correctly in "connect by" without using 'Start with' request?CP says:
I use "Connect By" query in a Join Condition.SELECT employee_id FROM employee e, dept d WHERE e.dept_id = d.dept_id AND e.employee_id = 100 START WITH manager_id IS NULL CONNECT BY PRIOR employee_id = manager_id;
Director ID may or may not be there. If the Manager id is NOT NULL, then this query fails. So need to connect by query without a Clause to start.
You seem a little confused on the hierarchical queries.
Let me put it this way: hierarchical queries are return of rows in a table, climbing from root to branches (or sheets if you prefer) or descendant of a branch (or sheets) to a root.
When you start, you have to say when you start from. This can be any value to your table.
I'll use the employees of HR schema provided with Oracle standard table here below.
Suppose you want to select the top-down hierarchy (or roots-sheets if you prefer) from employees_id = 108.
In this case, you can do like this:
SELECT employee_id, manager_id
FROM employees e
START WITH employee_id=108
CONNECT BY PRIOR employee_id = manager_id;
EMPLOYEE_ID MANAGER_ID
----------- ----------
108 101
109 108
110 108
111 108
112 108
113 108
Now you see that number 108 is also a Manager. If I change my request and I say I want to start with manager_id = 108, I'll start with the records having manager_id = 108. This is why employee_id = 108 will be excluded:
SELECT employee_id, manager_id
FROM employees e
START WITH manager_id=108
CONNECT BY PRIOR employee_id = manager_id;
EMPLOYEE_ID MANAGER_ID
----------- ----------
109 108
110 108
111 108
112 108
113 108
If you do not specify a START WITH clause, for each record in the table the top-down hierarchical query will be executed.
SELECT employee_id, manager_id
FROM employees e
-- START WITH employee_id=100
CONNECT BY PRIOR employee_id = manager_id
order by employee_id;
EMPLOYEE_ID MANAGER_ID
----------- ----------
100
101 100
101 100
102 100
102 100
....
206 205
206 205
206 205
206 205
315 rows selected.
I hope it's clear. If this isn't the case, please post more details about your question.
Kind regards.
Al
Tags: Database
Similar Questions
-
Understanding "CONNECT BY" and "START WITH".
OK, I'm trying to update the rows with values determined by lines joined in a recursive relationship of unknown depth. I am told that "CONNECT BY" and "START WITH" can be useful in this, but I don't see how to get the value I'm looking for.
In my case, there are 3 values in my table.
ID
ID of the parent
Invoice
On some lines, the Bill is null. For records, you get the ID of the invoice by searching for the invoice of the parent folder. I'm trying to update the table so that all THE rows in the table have an ID of invoice.
Here is an example of table and the lines.
What I would do is update the inv_num column in the table so that a select statement * would look like this...CREATE TABLE DISTRIBUTION ( ID INT, INV_NUM INT, PARENT_ID INT ) INSERT INTO DISTRIBUTION 1, 111, NULL; INSERT INTO DISTRIBUTION 2, 112, NULL; INSERT INTO DISTRIBUTION 3, NULL, 2; INSERT INTO DISTRIBUTION 4, 113, NULL; INSERT INTO DISTRIBUTION 5, NULL, 4; INSERT INTO DISTRIBUTION 6, NULL, 5; INSERT INTO DISTRIBUTION 7, NULL, 6;
You can provide any help would be greatly appreciated.ID INV_NUM PARENT_ID ----- ------------- --------------- 1 111 null 2 112 null 3 112 2 4 113 null 5 113 4 6 113 5 7 113 6
Hello
Thank you post the CREATE TABLE and INSERT instructions, but please make sure that they work.
None of the INSERT statements; I think you meant something like the statements shown after the query.Here's a way to get the desired results:
UPDATE distribution m SET inv_num = ( SELECT inv_num FROM distribution WHERE CONNECT_BY_ISLEAF = 1 START WITH id = m.id CONNECT BY id = PRIOR parent_id AND PRIOR inv_num IS NULL ) WHERE inv_num IS NULL ;
This statement is Bottom-Up of subqueries, where we START WITH the lines that need to update, and process to the top of the tree, until you get to an ancestor who was an inv_num.
In your sample data, only the roots (the lines that have no parents) have inv_num. In this case, it might be a little easier (but only a little) to make a request from top to bottom , where we START WITH the roots and low process in the tree to find their subordinates.
If we add some data examples where a nonroot has inv_num:INSERT INTO DISTRIBUTION (id, inv_num, parent_id) VALUES ( 91, 910, 1); INSERT INTO DISTRIBUTION (id, inv_num, parent_id) VALUES ( 92, NULL, 91);
What results would you like?
Using the UPDATE statement above, id = 92 would get his inv_nuym of the closest ancestor (in the case of thios, parent) who had an inv_num:. ID INV_NUM PARENT_ID ---------- ---------- ---------- 1 111 91 910 1 92 910 91 2 112 3 112 2 4 113 5 113 4 6 113 5 7 113 6
Either the row with id = 92 gets inv_num = 910, no 111.
-
WiFi connects immediately after starting
Hello community,
I started having Wifi issues after installation LittleSnitch. It would be irrelevant, but that's when the problem appeared. Although I have already removed, the Wifi connection does not seem to operate normally.
Before that, it would connect immediately after starting, which means instant access to Chrome or any other browser.
Now, he continues the search for a few seconds, shows an exclamation point on the wifi icon and then finally connects to my network. This process takes more than 30 seconds.
I tried several solutions spare, change my location, manual settings, DHCP or DNS, wifi diagnostics, reset my router, but all without success. I still can't get it to connect at the same time.
Any ideas?
(El capitan)
Please read this message before doing anything.
This procedure is a diagnostic test. It is unlikely to solve your problem. Don't be disappointed when you find that nothing has changed after you complete it.
The test is intended to determine if the problem is caused by a third-party software that loads automatically at startup or logon, by a device, by a police conflict or corruption of system files or some system caches.
Disconnect all devices wired except those required to test and remove all the expansion cards from secondary market, as appropriate. Start in safe mode and log on to the account of the problem.
Note: If FileVault is enabled in OS X 10.9 or an earlier version, or if a firmware password is defined, or if the boot volume is a software RAID, you can not do this. Ask for additional instructions.
Safe mode is much slower to boot and run as normal, with limited graphics performance, and some things work at all, including an audio output and a Wi - Fi connection on some models. The next normal boot can also be a bit slow.
The login screen is displayed even if you usually connect automatically. You need your password to log on. If you have forgotten the password, you will have to reset it before you begin.
Test in safe mode. Same problem?
After testing, restart as usual (not in safe mode) and make sure you always have the problem. View the results of the test.
-
No instant Wlan connection at the start of the Satellite L650
Hello
I had connection problems with my Toshiba L650 during the past two months.
I bought my laptop about a year ago (October 2010), and everything worked perfectly until April 2011.
The first months, my computer will automatically connect to the internet once it starts.From April 2011, my computer takes about 2 minutes to connect to a wireless internet connection when I start it, either my home connection or connection.
Once it does not connect, wireless works perfectly.The problem is not a wireless router because it happens with all wireless connections. Also, I tried to update the drivers for the network card wireless (Broadcom 802.11n) no success at all.
I would be grateful if someone could provide possible solutions to the problem.
Thanks in advance.So, what exactly is the problem?
The WiFi network connects well, but it takes two minutes until the connection has been established?
Right?Well, it might be possible that something is running in the background of the BONE and so it takes a while until the laptop been able to connect to the Wlan.
In my case, the laptop needs time to connect to the Wlan because the virus scanner and CCleaner run at startup and scans the HARD disk and the system.
After that, the laptop connects to the Wlan. -
Vista, loss of internet connection on cold start and restarts.
I use windows Vista, recently (after only 4 years of satisfactory used) I lose the internet connection on cold starting and restarting and duty use windows diagnostics to establish the connection. I bought a new Modem Sagem, and cable ethernet and filters, still the problems persists. ISP tells me that the problem is with Vista, can anyone help please?
The game may 17, 2012 03:43:10 + 0000, BIGKEV2257 wrote:
I am not satisfied by McAfee, three days and three nights, waiting for their technicians to ring me, I get automated emails asking if I'm happy and saying that they can not communicate with me, seems since Mr. McAfee sold his company, that it went to the pack, and I understand not why Microsoft sell McAfee with new computers when mcAfee are not appropriate technical support.
Two points:
1. in my opinion and that of many others of us here, McAfee is one of
the poorest choice of security these days software here. I strongly
recommend you take and replace with eSet NOD32 or
Kaspersky, if you are willing to pay for it. If you want a free
antivirus, I recommend one (do not run more than one antivirus
program) of three of the following:
Avira AntiVir
Avast
Microsoft Security Essentials
You also need anti-spyware software (even if you run a program such as)
Microsoft Security Essentials, with integrated anti-spyware capability
It). I recommend that you download and install MalwareBytes (freeware)
AntiMalware
2 Microsoft isn't selling McAfee with new computers. Microsoft
is not even do or do not sell computers. If your computer comes with
McAfee, it's because the manufacturer of your computer (Dell, HP,
Gateway, or anyone else) has chosen to sell like that.Ken Blake, Microsoft MVP
-
I have a paid subscription to cloud creative Illustrator and photshop. I had to make a computer reset due to windows 10 and now when I connect it says start trial?
-
Can the vcenter server that an ESX host is connected to determine through query of the esx host cmd line?
All points will be awarded. Thxs.
Look in
/etc/opt/vmware/vpxa/vpxa.cfg
you will see that the IP VCMS listed something like
1.1.1.1 -
Hierarchical connect by and start with and joined?
I have an Employees table and a table of identifiers. The table of identifiers is hierarchical, with parents and children. Each employee has one or more identifiers, but that a unique identifier is considered to be the "primary" or root for each employee identifier. Unfortunately, the employee table can point to one of the children identifier lines and not the root. I need a quick query to reach employees with their most recent ID (root).
Here's the code to define the problem.
What I want is to put the parent node above realids for each line of employees...create table employees (employeeid varchar2(8), fakeNationalID varchar2(9), empname varchar2(30)); insert into employees (employeeid, fakeNationalID, empname) values (1,'001000001','John Smith'); insert into employees (employeeid, fakeNationalID, empname) values (2,'002000002','James Jones'); create table realids (realidkey NUMBER, fakeNationalID VARCHAR2(9) not null, realNationalID VARCHAR2(9) UNIQUE, parent_realidkey number); insert into realids (realidkey, fakeNationalID, realNationalID, parent_realidkey) values (1,'001000001','111111111',3); insert into realids (realidkey, fakeNationalID, realNationalID, parent_realidkey) values (2,'002000002','222222222',null); insert into realids (realidkey, fakeNationalID, realNationalID, parent_realidkey) values (3,'003000003','333333333',null); commit; create or replace function get_parentid (fakeID in VARCHAR2) return varchar2 is tempid VARCHAR2(9); begin select realNationalID into tempid from ( select realNationalID, fakeNationalID from realids start with fakeNationalID = fakeID connect by nocycle prior parent_realidkey = realidkey order by level desc) where rownum = 1; return tempid; exception when NO_DATA_FOUND then return NULL; when others then raise; end; select get_parentid('001000001') from dual; -- returns 333333333 because its linked to a parent select get_parentid('002000002') from dual; -- returns 222222222 because there is only one child select get_parentid('003000003') from dual; -- returns 333333333 because it is the parent
It works, but it is NOT very effective:
You can imagine what it would be like with 100K lines or more. It takes about 3 minutes to run.select employeeid, get_parentid(fakeNationalID) realid, empname from employees; employeeid realid empname ---------- ----------- ------------ 1 333333333 John Smith 2 222222222 James Jones
It seemed like a good way to do it, but with a sub query.
Unfortunately, it produces an invalid identifier on e.fakenationalid (in the beginning with the clause).select e.employeeid, e.fakenationalid, e.empname, sub.realnationalid from employees, (select realidkey, fakenationalid, realnationalid, parent_realidkey from realids r start with r.fakenationalid = e.fakenationalid connect by prior r.parent_realidkey = r.realidkey) sub
Anyone has any ideas on how to get top most parent node of the realids for each row in the employees table? In real life, there are 6 or more employees tables across multiple remote instances of what children in the realids table and how much to the parents. We always want the highest parent of the page realid. Any help would be appreciated.Hello
Thanks for posting the sample data in a convenient form!
It is always useful to post your version of Oracle, too, especially when it comes with CONNECT BY queries.What follows is what you asked for in Oracle 10:
WITH got_roots AS ( SELECT CONNECT_BY_ROOT fakenationalid AS leaf_id , realnationalid FROM realids WHERE CONNECT_BY_ISLEAF = 1 START WITH fakenationalid IN ( SELECT fakenationalid FROM employees ) CONNECT BY realidKEY = PRIOR parent_realidkey ) SELECT e.employeeid , r.realnationalid , e.empname FROM employees e JOIN got_roots r ON r.leaf_id = e.fakenationalid ;
In any query, call a function defined by the user for each line is going to be slow. Fortunately, Oracle now has the built-in functions and operators that can take the place of get_parentid. The CONNECT_BY_ROOT operator, which was introduced in Oracle 10, is the key to the problem. In Oracle 9, you can get the same results using SYS_CONNECT_BY_PATH.
It is generally faster to CONNECT BY query separately, and then join some other tables you need for results.
You had a good idea in your last query. The problem was that void and employees were equal tables in the FROM clause, and you cannot establish a correlation between equals. You can only correlate a subquery to its Super application. You could make to this general idea work by changing void in a scalar sub-requete, which can be connected to the employees, but I think it would be much less effective than what I posted above.
-
Performance issue with connection of a level query
Hi I have a problem with connection by level in oracle.
My table is:
J_USER_CALENDAR
--------------------------
USER_NAME FROM_DATE TO TO_DATE COMMENTS
-------------------------------------------------------------------------------------------------
Comment1 5 November 09 uma Shankar 2 November 09
Veera 11 November 09 13 November 09 Comment2
Commnet3 17 December 09 uma Shankar 15 December 09
Vinod 20 October 09 21 October 09 Comments4
The table above is the calendar of user authorization.
Now I need to view the users who are on leave between November 1, 2009 to November 30, 2009
The output should look like:
USER_NAME FROM_DATE COMMENTS
---------------------------------------------------------------------------------
Comment1 2 November 09 uma Shankar
Comment1 3 November 09 uma Shankar
Comment1 4 November 09 uma Shankar
Comment1 5 November 09 uma Shankar
Comment2 Veera 11 November 09
Comment2 Veera 12 November 09
Comment2 Veera 13 November 09
For this, I tried with the following query, but it takes too long to run.
Select FROM_DATE, user_name, comments from (SELECT distinct FROM_DATE, user_name,
Comments FROM (SELECT (LEVEL) + FROM_DATE-1 FROM_DATE, TO_DATE, FIRST_NAME |) » '|| LAST_NAME
user_name, COMMENTS OF J_USER_CALENDAR
where
and J_USER_CALENDAR.IS_DELETED = 0
CONNECT BY LEVEL < = TO_DATE - FROM_DATE + 1) has) where ("FROM_DATE = 1st November 2009 ' or FROM_DATE = November 30, 2009")
or FROM_DATE between November 1, 2009 "-November 30, 2009") order of from_Date, lower (user_name)
Please help me.
Thanks in advance.
Kind regards
PhanikanthI have not tried to analyze the SQL statement.
Here is a test set in place:
CREATE TABLE T1( USERNAME VARCHAR2(30), FROM_DATE DATE, TO_DATE DATE, COMMENTS VARCHAR2(100)); INSERT INTO T1 VALUES ('Uma Shankar', '02-Nov-09','05-Nov-09','Comment1'); INSERT INTO T1 VALUES ('Veera','11-Nov-09','13-Nov-09','Comment2'); INSERT INTO T1 VALUES ('Uma Shankar','15-Dec-09','17-Dec-09','Commnet3'); INSERT INTO T1 VALUES ('Vinod','20-Oct-09','21-Oct-09','Comments4'); INSERT INTO T1 VALUES ('Mo','20-Oct-09','05-NOV-09','Comments4'); COMMIT;
Note that I have included an additional line, when the person starts their vacation in the previous month and ends in November.
You could approach the problem like this:
Assume that you want to appear every day in a given month:SELECT TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY FROM DUAL CONNECT BY LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY');
Note that the above attempts to calculate the number of days in the month of November - if we know that the month has a certain number of days, 30 for example, you can rewrite the CONNECT BY clause like this:
CONNECT BY LEVEL<=30
Now, he must pick up lines of interest to the table:
SELECT * FROM T1 T WHERE (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY') OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')); USERNAME FROM_DATE TO_DATE COMMENTS --------------- --------- --------- ---------- Uma Shankar 02-NOV-09 05-NOV-09 Comment1 Veera 11-NOV-09 13-NOV-09 Comment2 Mo 20-OCT-09 05-NOV-09 Comments4
If join us then both sets of results, we have the following query:
SELECT * FROM T1 T, (SELECT TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY FROM DUAL CONNECT BY LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY')) V WHERE (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY') OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')) AND V.MONTH_DAY BETWEEN T.FROM_DATE AND T.TO_DATE ORDER BY USERNAME, MONTH_DAY; USERNAME FROM_DATE TO_DATE COMMENTS MONTH_DAY --------------- --------- --------- ---------- --------- Mo 20-OCT-09 05-NOV-09 Comments4 01-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 02-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 03-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 04-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 05-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 02-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 03-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 04-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 05-NOV-09 Veera 11-NOV-09 13-NOV-09 Comment2 11-NOV-09 Veera 11-NOV-09 13-NOV-09 Comment2 12-NOV-09 Veera 11-NOV-09 13-NOV-09 Comment2 13-NOV-09
Charles Hooper
IT Manager/Oracle DBA
K & M-making Machine, Inc. -
Cannot move to the start page of Mozilla. Any site or search I run, I get a message that Mozilla can not establish a connection with the server.
See this support article - difficulty of problems connecting to websites after Firefox update
-
No cursor on the screen to connect to the start or restart
Hello, my missing cursor problem is a little different from others, I have not installed VMware, or use a wireless keyboard/mouse. And happen randomly when using the laptop. Also the alarm clock is correct because I only need to enter a password, don't choose between accounts.
My 13 "mid 2012 retina not MBP was having no problem connecting with 10.11.1. But when I upgraded to 10.11.2 I started having a problem. After that my lap top boots and I just login/password page, there is no mouse cursor for me to click on the user account icon for the password box. This only happens at the start or restart. It occurs only if I got my MBP in hibernation for a few hours and restarted (I run Onyx to clean and a restart is recommended), but now it happens if I had turned it off overnight.
If I close the lid and put it to sleep for 5 to 10 seconds, and then reopen the lid. I get a black screen for about 5 seconds then the normal login screen returns with a slider and I can connect normally I remember once having to close the cover once more.
I 'fix' this during a few days by turning off bluetooth in sys. Pref. For some reason, upgrading to 10.11.2 re-enabled bluetooth. But a few days ago the missing number of slider reappeared.
Today, I tried something different. I used the trackpad to drag the top slider of 'invisible' to the left corner where he usually is at the start and crept above where to seat my account icon. I guessed correctly (had) and was able to click the icon cursor haha. So connect is not buggy, just no cursor.
If this sounds familiar to anyone or anyone has any advice, I would really appreciate it. I prefer not to do a clean install. Maybe safely remove a demon plist or launch work? Thank you!
Same problem on a MacBook Pro (15-inch, mid-2012). El Capitan 10.11.3
No solution, but the problem for me is very sparatic and doesn't happen very often.
-
Turn off connection at the start of the VI
Hello
When you start VI adverse action occurs - polarization [i] value is stored in flip-flop (please, see the screenshot below).
There are some tecjnique, that allow to disable a connection (red on the screenshot) for a few moments at the start of VI.
Thanks in advance
Pavel
What the hell...? You are 'i' adding to itself exponentially and compare that to 100... So every time, your code will look like this:
0 + 0 = 0<>
0 + 1 = 1<>
1 + 2 = 3<>
3 + 3 = 6<>
6 + 4 = 10<>
10 + 5 = 15<>
15 + 6 = 21<>
21 + 7 = 28<>
28 + 8 = 36<>
...
91 + 14 = 105 100 >
It's round point rediculously. If this reeeaaally works for you, just on the logic "AND I have 13 >.
-
cannot connect on the start page, as the owner.
computer froze on the star page. cannot connect as an owner.
Hi mycasmas,
1. don't you make changes before the show?
2. the problem persists with other users accounts?Step 1: We recommend that you check if the problem persists in safe mode
a. see Description of the Mode of course in Windows XP startup options
b. in the menu advanced startup options select Safe mode and press on enter.
c. connect to your user account.Step 2: If the problem does not persist in safe mode, check if a non-Microsoft program is causing the problem
see How to configure Windows XP to start in a "clean boot" State .
b. in the article, follow the method 1 and method 2 to find out if any program is causing the problem.
c. Once you have found the culprit that is the program that is causing the problem, then uninstall it.Note: Article, remember to follow 'steps to configure Windows to use a Normal startup state. "
Visit our Microsoft answers feedback Forum and let us know what you think.
-
How can I put/pin a shortcut to "manage network connections" in the start menu?
The window "manage network connections", I want to talk about is one that can be found on the left side of the window "Network and sharing Center", placed under the heading 'Tasks'
Manually open to this place... All the way you want to manage the connections then.
Drag the icon in the 'address bar' above to your desktop or start menu, or the taskbar, etc... It will create a shortcut.
-
Using windows 7 I have a drive NAS that I need to connect manually whenever my machine that we start - I want that he remember details of connection and do it automatically at startup of the machine because it is also used by my wife and I want auto backup to run.
Using the Credential Manager in Windows 7 to remember the username and password for your NAS drive if she don't remember automatically.
Go to start / Control Panel / user accounts and family safety / Credential Manager
On the right side, just below where it says "Windows credentials" select "add a Windows credential.
In the first box, enter the name of your NAS server.
User name in the second box and your password for the server in the third area.
Maybe you are looking for
-
After several years of replacement ink cartridges very well, when the upper part is called the carrier of ink does not move to the Center. It does not move at all. Help!
-
How can I send feedback to Microsoft streets & trips
Just tired of MS pretty much ignoring problems with ST. SO, I just wanted to say a few bodies in MS I think. But all I get are these automated forms that seem to go no the case. ST regularly went to the bottom of the Hill because I had my first in 20
-
How can I find the password that I used when I got my computer?
I want to clean my hard drive and start from scratch, but I don't remember my password... Is there a way to get this information?
-
drivers for windows ultimate 64-bit
I have a hp 4530 and the final Windows 7 I have loaded is not all drivers. am looking for a package with all the drivers.
-
I want to sign Carolina but now get the error 'Windows command summary page is not currently available. Please try again later. »