CONNECT BY loop in user data in Oracle

Posted By  Nimish Garg On 18 Feb 2011 19:02:24
emailbookmarkadd commentsprint
No of Views:655
Bookmarked:0 times
Votes:0 times

Introduction

In this tip,i will explain  how to use CONNECT BY loop in user data and fetch data.

Lets assume our data is:

select * from emp;

 

Image Loading

when we execute a hierarchical query, it throws an error as

select empno, ename, sys_connect_by_path(ename,' -> ') tree from emp connect by prior empno=mgrno;

 

Image Loading

To trace this error of Connet by loop using connect_by_iscycle, we may execute following query:

select emp.*, connect_by_iscycle from emp where connect_by_iscycle = 1 connect by nocycle prior empno=mgrno;

 

Image Loading

and now we can correct this cyclic loop as:

update emp set mgrno=2497 where empno=3061;

and execute our previous hierarchical query

select empno, ename, sys_connect_by_path(ename,' -> ') tree from emp connect by prior empno=mgrno;

 

Image Loading

That's all.hopes help.

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top