ORA-01436 CONNECT BY loop in user data


Problem:  When traversing a database table to find the hierachy of parent child (like manager, employee), this error happens

ORA-01436 CONNECT BY loop in user data

Solution:  If SQL Query looks like

select * from customer

start with manager_id = ‘334’

connect by prior emp_id = manager_id

above problem can happen, if the next record that is to be selected is a descendent of itself, which causes loop problem. By having another condition like below

 

select * from customer

start with manager_id = ‘334’

connect by prior emp_id = manager_id

AND relationship_cd = ‘IS MANAGER OF’

retrieves all the employees whose manager is either 334 and also those employees whose manager is children of manager 334

 

 

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: