Connect by loop help
Hi,
I have a table with 4 columns
parent number,
parent code varchar2(10),
child number,
child code varchar2(10)
The parent code and child code are catogries and the parent and child are IDs both have to be equal to each other for there to be a link.
i.e. a child 200 code 'C' with a parent 100 code 'T' only relatest to parent 100 code 'T'. There can be a parent 100 code 'C' and 'P' etc.
I am after a connect by loop that will give me all the relationships that this table contains.
Any help please
So what you want is something like this?
SQL> ed
Wrote file afiedt.buf
1 with t as (select &id as id, '&code' as code from dual)
2 --
3 select 'Child' as type, pcchild as id, pcchildcode as code
4 from afpc, t
5 connect by pcparent = prior pcchild and pcparentcode = prior pcchildcode
6 start with pcparent = id and pcparentcode = code
7 union all
8 select 'Parent' as type, pcparent as id, pcparentcode as code
9 from afpc, t
10 connect by pcchild = prior pcparent and pcchildcode = prior pcparentcode
11* start with pcchild = id and pcchildcode = code
SQL> /
Enter value for id: 1960
Enter value for code: ACT
old 1: with t as (select &id as id, '&code' as code from dual)
new 1: with t as (select 1960 as id, 'ACT' as code from dual)
TYPE ID CODE
Child 1957 ACT
Child 1961 ACT
Parent 2916 CAS
SQL> insert into afpc values (7, 3000, 'TST', 2916, 'CAS');
1 row created.
SQL> with t as (select &id as id, '&code' as code from dual)
2 --
3 select 'Child' as type, pcchild as id, pcchildcode as code
4 from afpc, t
5 connect by pcparent = prior pcchild and pcparentcode = prior pcchildcode
6 start with pcparent = id and pcparentcode = code
7 union all
8 select 'Parent' as type, pcparent as id, pcparentcode as code
9 from afpc, t
10 connect by pcchild = prior pcparent and pcchildcode = prior pcparentcode
11 start with pcchild = id and pcchildcode = code
12 /
Enter value for id: 1960
Enter value for code: ACT
old 1: with t as (select &id as id, '&code' as code from dual)
new 1: with t as (select 1960 as id, 'ACT' as code from dual)
TYPE ID CODE
Child 1957 ACT
Child 1961 ACT
Parent 2916 CAS
Parent 3000 TST
SQL>
Similar Messages
-
Need help in resolving CONNECT BY loop in user data in Oracle 9.2.0.5 Ver
Hi Everyone,
Below are the scripts to reproduce the error
CREATE TABLE TESTING
C1 NUMBER,
C2 NUMBER,
GRP NUMBER
Insert into TESTING
(C1, C2, GRP)
Values
(1, 2, 100);
Insert into TESTING
(C1, C2, GRP)
Values
(1, 3, 100);
Insert into TESTING
(C1, C2, GRP)
Values
(2, 5, 200);
Insert into TESTING
(C1, C2, GRP)
Values
(3, 11, 200);
Insert into TESTING
(C1, C2, GRP)
Values
(11, 1, 400);
COMMIT;
SELECT sys_connect_by_path(C1,'/') AS C1,C2
FROM TESTING
CONNECT BY C1 = PRIOR C2
I am getting "ORA-01436: CONNECT BY loop in user data" because of Recurssion.
My Oracle Version is 9.2.0.5, can you guide me how to resolve in 9.2.0.5
In Oracle 10g I have read that we can achieve through NOCYCLE option
Can you please guide me how to solve this in Oracle 9.2.0.5 Version
Thanks in Advance,
SankarSQL> SELECT SYS_CONNECT_BY_PATH (c1, '/') AS c1, c2
2 FROM testing
3 CONNECT BY c1 = PRIOR c2 AND (c2 >= PRIOR c1);
C1 C2
/1 2
/1/2 5
/1 3
/1/3 11
/2 5
/3 11
/11 1
7 ligne(s) sélectionnée(s).
SQL> -
i tried updating my ipod, and then it turned off, and then just said connect to itunes, and when i did, it said i had to restore it. so, i restored it, and it did nothing and still said connect to itunes. help?
Try:
- iOS: Not responding or does not turn on
- Also try DFU mode after try recovery mode
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
- If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
- Try on another computer
- If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
Apple Retail Store - Genius Bar
or
Maybe:
Restore loop (being prompted to restore again after a restore successfully completes)
Troubleshoot your USB connection. If the issue persists, out-of-date or incorrectly configured third-party security software may be causing this issue. Please follow Troubleshooting security software issues. .
Next try placing in DFU mode and then restoring.
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
Then try restoring on another computer.
Last, make an appointment at the Genius Bar of an Apple store.
Apple Retail Store - Genius Bar -
Hi friends,
When i tried to execute my below query im getting error like
ORA-01436: CONNECT BY LOOP IN USER DATAThis is my query
select distinct papf.person_id, papf.full_name "Employee Name", supf.full_name "Manager Name", paaf.supervisor_id, level
from per_all_people_f papf, per_all_people_f supf, per_all_assignments_f paaf
where papf.person_id = paaf.person_id and nvl(paaf.supervisor_id, papf.person_id) = supf.person_id and
trunc(sysdate) between paaf.effective_start_date and PAAF.effective_end_date and
trunc(sysdate) between papf.effective_start_date and PApF.effective_end_date
start with paaf.supervisor_id is null
connect by prior papf.person_id = PAAF.supervisor_id
order by papf.person_idWhere i went wrong, could understand the cause.
Thanks
Regards,
VelHi, Vel,
ORA-01436 occurs when a row is its own descendant. This is usually caused by bad data; you may not have done anything wrong.
If you say CONNECT BY NOCYCLE (instead of just CONNECT BY) then the error will not be raised, but that doesn't mean the problem is fixed. If you do have bad data in your tables, you need to track that down and fix it.
This might help you find the rows that are causing the problem:
WITH problem_children AS
select distinct papf.person_id --, papf.full_name "Employee Name", supf.full_name "Manager Name", paaf.supervisor_id, level
from per_all_people_f papf, per_all_people_f supf, per_all_assignments_f paaf
where papf.person_id = paaf.person_id and nvl(paaf.supervisor_id, papf.person_id) = supf.person_id and
trunc(sysdate) between paaf.effective_start_date and PAAF.effective_end_date and
trunc(sysdate) between papf.effective_start_date and PApF.effective_end_date
AND CONNECT_BY_ISCYCLE = 1
start with paaf.supervisor_id is null
connect by NOCYCLE prior papf.person_id = PAAF.supervisor_id
-- order by papf.person_id
select distinct papf.person_id, papf.full_name "Employee Name", supf.full_name "Manager Name", paaf.supervisor_id, level
, CONNECT_BY_ISCYCLE AS iscycle
from per_all_people_f papf, per_all_people_f supf, per_all_assignments_f paaf
where papf.person_id = paaf.person_id and nvl(paaf.supervisor_id, papf.person_id) = supf.person_id and
trunc(sysdate) between paaf.effective_start_date and PAAF.effective_end_date and
trunc(sysdate) between papf.effective_start_date and PApF.effective_end_date
start with papf.person_in IN (
SELECT person_id
FROM problem_children
connect by NOCYCLE prior papf.person_id = PAAF.supervisor_id
;If you need help. post the output of the query above, CREATE TABLE statements for the tables involved (relevant columns only), and your code. Format both your results and your code so people can read and understand them. See the forum FAQ {message:id=9360002} fr how to use \ tags to post formated text. -
Oracle SSHR (Absence Management) Error - ORA-01436: CONNECT BY LOOP
The following error message is displayed in Absence Review Page while creating a Leave of Absence for some employees, while working propoerly (withpout any error) for other employees,
"An Invalid Setup has been detected for the current Transaction Type in Approvals Management. Please contact your System Administrator."
Please note that I checked the Supervisory chain through the follwoing query and it shows data properly without any endless loop,
SELECT levels, ppf.full_name, ppf.Employee_number
FROM per_all_people_f ppf,
(SELECT level levels, paf.person_id
FROM per_all_assignments_f paf START WITH paf.person_id = &person_id
AND paf.primary_flag = 'Y'
AND SYSDATE BETWEEN paf.effective_start_date
AND paf.effective_end_date CONNECT BY PRIOR paf.supervisor_id = paf.person_id
AND paf.primary_flag = 'Y'
AND SYSDATE BETWEEN paf.effective_start_date
AND paf.effective_end_date ORDER BY LEVEL) paf
WHERE ppf.person_id = paf.person_id
AND SYSDATE BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
ORDER BY levels
further it may please be noted that we have currently set a singly level for approval (testing purposes).
Any help to resolve this issue shall be highly appriciable.
Regards,
Nahidullah KhanPlease also see the following docs.
Invalid Setup Has Been Detected For The Current Transaction Type In Approvals Management [ID 1313961.1]
An Invalid Setup has been detected for the current Transaction Type in Approvals Management. [ID 602920.1]
An Invalid Setup Has Been Detected For The Current Transaction Type In Approvals Management. ORA-06502: PL/SQL: numeric or value error: Character string buffer too small [ID 1458422.1
An Invalid setup has been detected for the current transaction type [ID 1300417.1]
Connect By Loop Problem in Supervisor Hierarchy [ID 579750.1]
Initiating A Transaction That Goes For Approval Fails With ORA-06502 [ID 795063.1]
Thanks,
Hussein -
ORA-01436 : CONNECT BY loop - is sequence of keys important?
Hi everyone
I'm seeing an ORA-01436 error - CONNECT BY loop in user data - when I'm running the query below:
select distinct(pose.organization_id_child)
from per_org_structure_elements pose
where pose.org_structure_version_id =
(select posv.org_structure_version_id
from per_org_structure_versions posv
where trunc(sysdate) between posv.date_from and nvl(posv.date_to,'31-DEC-4712'))
start with pose.organization_id_parent = xxx
connect by prior pose.organization_id_child = pose.organization_id_parent;
(I'm connecting to a Oracle9i Enterprise Edition Release 9.2.0.8.0 database by the way)
This error doesn't always crop up - if I change the organization_id_parent value in the start with section of the query above, I find that it only happens for certain organization_ids. However, for the organization_ids where it does happen, upon examining the data for both parent and child rows, I can't understand why a CONNECT BY loop might be happening.
For example, the two rows below cause issues whenever I try to use their organization_id_parent in the query:
Senior Store Manager level (second from bottom):
ORG_STRUCTURE_ELEMENT_ID 34305
BUSINESS_GROUP_ID 1
ORGANIZATION_ID_PARENT 667
ORG_STRUCTURE_VERSION_ID 224
ORGANIZATION_ID_CHILD 571
Store level (bottom level):
ORG_STRUCTURE_ELEMENT_ID 34304
BUSINESS_GROUP_ID 1
ORGANIZATION_ID_PARENT 571
ORG_STRUCTURE_VERSION_ID 224
ORGANIZATION_ID_CHILD 570
As you can see, the org_id_parent value at the bottom level is greater than the actual org_id_child value at that same level. Could this be what is causing the ORA-01436 error? It's the only thing that's come to mind so far!
Any help would be gratefully received.
Thanks, Geoffuser11979984 wrote:
Thanks for that Frank, that's cleared it up a bit! I'm still a bit mystified as to the results I'm getting when I switch the statements but at least that sheds some light on it.
In response to your query as to why my original query has a DISTINCT in it, the answer is that if you're sitting near the top of the hierarchy, you could have a whole heap of zones and regions reporting to you, each of which has their own sets of stores. Without the DISTINCT, you could have the same org id for a region or a zone returned multiple times depending on how many stores they have reporting to them.I'm not sure I agree with you 100% on your police work there.
In a well-formed tree (where each node has, at most, one parent), if the START WITH clause only includes unrelated nodes, then no node will appear more than once.
For example, consider the basic CONNECT BY query from scott.emp:
SELECT LPAD ( ' '
, 2 * (LEVEL - 1)
) || ename AS indented_name
, LEVEL
, empno
, mgr
FROM scott.emp
START WITH mgr IS NULL
CONNECT BY mgr = PRIOR empno
;Output:
INDENTED_NAME LEVEL EMPNO MGR
KING 1 7839
JONES 2 7566 7839
SCOTT 3 7788 7566
ADAMS 4 7876 7788
FORD 3 7902 7566
SMITH 4 7369 7902
BLAKE 2 7698 7839
ALLEN 3 7499 7698
WARD 3 7521 7698
MARTIN 3 7654 7698
TURNER 3 7844 7698
JAMES 3 7900 7698
CLARK 2 7782 7839
MILLER 3 7934 7782
14 rows selected.Here KING has 3 children, who in turn have between 1 and 5 children each, and some of them have children of their own, but every one of the 14 rows in the table appears exactly once, without using SELECT DISTINCT.
The scott.emp table has a very clean design. If you have to do more complicated queries (e.g. SELECT DISTINCT), then I suspect your table design is not as clean. Without knowing exactly what it is, there's a limit on how much I can help you.
One question that's always bugged me with this issue is whether the PRIOR operator expects the parent id for a child record to be numerically inferior to the child id e.g. if parent id is 561, then any child ids in the hierarchy should be 562 or greater? This doesn't appear to be the case with our hierarchy, but that doesn't explain why these errors are occurring if that is the case.No, the ids used can be completely arbitrary.
Look at scott.emp, above, where the relationships are indicated by empno. Sometimes a boss has a higher empno than an underling (KING is 7839, JONES is 7566); somethimes it's the other way around (JONES is 7566, SCOTT is 7788). -
Hi everbody,
Please a need some help with this:
I'm learning about how to generate rows in oracle from the page.
http://blog.lishman.com/2008/02/how-to-generate-rows-in-oracle_2477.html
In that page there is an example like this:
SELECT rownum
FROM dual
CONNECT BY LEVEL <= 5;
I execute this sentence in my oracle 8i database but a get this message: CONNECT BY loop in user data
Please,where is the problem?
Thanks in advanceuser491853 wrote:
Thank you justin !
I need to execute this query, because I need to find what 'TUESDAYS' are between 2 dates:
SELECT t.dt, TRIM (TO_CHAR (t.dt, 'DAY')) "DAY"
FROM (SELECT TRUNC (SYSDATE) + ROWNUM dt
FROM DUAL
CONNECT BY LEVEL <= 80) t
WHERE TRIM (TO_CHAR (t.dt, 'DAY')) = 'THURSDAY'
AND t.dt BETWEEN TO_DATE ('01/08/2006', 'dd/mm/rrrr')
AND TO_DATE ('31/08/2006', 'dd/mm/rrrr')
The result would be:
DT DAY
03-AUG-06 THURSDAY
10-AUG-06 THURSDAY
17-AUG-06 THURSDAY
24-AUG-06 THURSDAY
31-AUG-06 THURSDAY
How can I execute a similar query in oracle 8i? Thanks buddy for any response.I can't test it as I don't have access to 8i but does following query work (to generate rows)?
SELECT level
FROM DUAL
CONNECT BY LEVEL <= 80
AND PRIOR dbms_random.random IS NOT NULL ; -
ORA-01436: CONNECT BY loop in user data
We are using Oracle HR Manager Self Service and using the menu option, Worker Status Change, the subject error message appears when an attempt is made to submitted for approval.
Any suggestions as to what could be causing this?
Thanks,
LeePlease post the details of the application release, database version and OS.
We are using Oracle HR Manager Self Service and using the menu option, Worker Status Change, the subject error message appears when an attempt is made to submitted for approval.
Any suggestions as to what could be causing this?Please review these docs and see if it helps.
SSHR - ORA-01436 Connect By Loop Error In User Data In Manager Self Service [ID 333630.1]
PER_449800_ORA_1436 When Clicking On Manager Actions Links [ID 427428.1]
Ora-01436: Connect By Loop In User Data Ora-06512: At "Apps.Hr_security_internal [ID 873617.1]
ORA-01436: CONNECT BY LOOP in user data in SSHR [ID 275819.1]
SSHR: ORA-01436: Connect By Loop In User Data [ID 357718.1]
Configuring Oracle Self-Service Human Resources (SSHR) Approvals Using Approvals Management (AME) [ID 360515.1]
Thanks,
Hussein -
HTTP connection authentication - Please Help
I need to call a URL (that passes user and password parameters) to log on.
Next, I need to call another (and different) URL to perform an insertion. This operation requires the user to be logged on. I could not establish the authentication via HTTP connection.
ANY HELP WILL BE GRATLY APPRECIATED.
This is my source code:
URL url = new URL("http://myserver/validate?
as_user=X&as_password=Y");
URL url2 = new URL("http://myserver/save?as_categ_id=82");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader
(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
connection = url2.openConnection();
in = new BufferedReader(new InputStreamReader (connection.getInputStream()));
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
bufferedWriter.write(inputLine);
bufferedWriter.flush();
in.close();
}catch(Exception x){}
Thanks in advance.
nullHi,
your problem is very simple.
The class java.util.Vector has no methods get() without parameter and no method next().
Try using a for-loop with oprNames.size() and method get(i) with i as your index. -
I just got the new ipod touch (5th generation) and it will show up on my computer but it will not show up on itunes and it won't connect. Please help!
See:
iOS: Device not recognized in iTunes for Windows
You need iTunes version 10.7 -
while updating my ipad to new software through itunes it got stuck and does not work anymore - it just displays the screen with symbols of itunes and the cable to connect to it - help - what should i do?
Disconnect the iPad, do a Reset [Hold the Home and Sleep/Wake buttons down together for 10 seconds or so (until the Apple logo appears) and then release. The screen will go blank and then power ON again in the normal way.] It is 'appsolutely' safe!, reconnect and follow the prompts.
If that does not work then see here http://support.apple.com/kb/HT1808 -
I have an iPod 4th gen that up until the week before was connecting and charging fine on my desktop computer (running Windows 7(64-bit)). Now, when connected to the USB ports on my desktop, it goes into this rapid and unending connect/disconnect loop, never staying connected long enough to even be recognized by the computer. There is an error message that also says that charging is not supported by the computer, when before, things were fine. Despite all the problems on the desktop, the iPod is recognized fine by my 5 year old laptop, which is running a simplified version Windows XP. Halp. I've tried everything on the iPod support pages regarding this issue, and would really like to avoid calling Apple about this. Any suggestions?
Try putting it is DFU mode:
http://www.ijailbreak.com/apple_news/using-dfu-mode-to-fix-ipod-touch-and-iphone -errors/ -
I have problem with my ipad , when i want to update ios 6 to 6.0.1 this message appear " unable to verify update , ios 6.0.1 faild verification because you are no longer connected to the internet" but my ipad is connected . Plz help me .
Not very helpful but I have the same issue. Plugging in and doing the update via. iTunes will probably work but I find that whole experience annoying (downloading apps not on the Mac, etc..)
-
Error : CONNECT BY loop in user data
Getting CONNECT BY loop in user data:
Table X (sample data actually have 35K rows)
CODE CASE OLD_ID NEW_ID PERSON AUTH
01 ab122 1234 0001 AU123 99393
07 vv353 7872 0919 FV982 78282
01 ab122 1982 9929 AU123 99393
04 hjsss 8839 8302 JK920 32320
01 ab122 0001 1982 AU123 99393
05 cg899 6728 32322 IKL020 65252
07 w353 0919 8282 FV982 78282
now I need to order this data comparing row values of old_id to new_id for each of the combinations of code, person, case
need output like below
Table X
CODE CASE OLD_ID NEW_ID PERSON AUTH
01 ab122 1234 0001 AU123 99393
01 ab122 0001 1982 AU123 99393
01 ab122 1982 9929 AU123 99393
04 hjsss 8839 8302 JK920 32320
05 cg899 6728 32322 IKL020 65252
07 vv353 7872 0919 FV982 78282
07 w353 0919 8282 FV982 78282
to get this I am using:
--Query--
select * from table_x
start with old_id not in(
select new_id
from table_x
CONNECT BY old_id = PRIOR new_id
AND code = PRIOR code
AND case = PRIOR case
AND person = PRIOR person
--Query--
runs fine with sample data but the problem is when excute it with actual table that has 35K records..
Cause: The condition specified in a CONNECT BY clause caused a loop in the query, where the next record to be selected is a descendent of itself. When this happens, there can be no end to the query.
Action: Check the CONNECT BY clause and remove the circular reference.
Thanks,
AKHi,
CONNECT_BY_ISCYCLE is a pseudo-column that you can use in a CONNECT BY NOCYCLE query. It's separate from the CONNECT BY clause.
Try this:
select code, "CASE", person
, SYS_CONNECT_BY_PATH (old_id, '/') AS path
from table_x
where CONNECT_BY_ISCYCLE = 1
start with old_id not in (
select new_id
from table_x
CONNECT BY NOCYCLE old_id = PRIOR new_id
AND code = PRIOR code
AND "CASE" = PRIOR "CASE"
AND person = PRIOR person
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002#9362002 -
I need help my computer isn't working and there is no was to get on my iTunes and I just updated my phone and now it's stuck on where it shows the plug connected to iTunes help!!!!
There is no other way than to plug into a computer to restore the phone. You can use another computer to do so, but in case you did not back up to iCloud your data and settings will be gone.
Follow this article to connect in recovery mode:
iOS: Unable to update or restore
Maybe you are looking for
-
What is up with this mysterious battery??
So, I recently asked about a battery which is not charging.... it's plugged in, shows the charging symbol on the screen. I reset the SMC (or whatever) , and after two times, it worked and the battery charged like normal. But now, it's doing the same
-
How to launch My Own Application by clicking a embedded link in iPhone
Hi All Does anyone know how to launch my own application by clicking a embedded link in iPhone? same thing like you click a phone number , and then the phone application will be launched. Thanks -Tommy
-
What about copy and paste builds?
In Keynote 2 you can copy and paste attributes which really helps if you are doing an intense project. What would have been great was if Keynote 3 offered you to copy and paste builds as well. I have read here that you can make masters and build the.
-
I have no problems (this time) with making albums and running slideshows on the laptop, but when burning that album to a dvd (export and burn) the sequences are going back to the Nikon/iPhoto Library date sequence and therefore out of album order....
-
How to override cartridge empty message and continue printing on Officejet Pro 8600
Hi, I'm setting up a new OfficeJet Pro 8600 printer for my parents. On my HP color laser printer I am able to override the setting where the printer stops printing because it hit a date or page quantity. My parents don't print complex, color docume