Context:
Let's say that I have table that has a FOREIGN KEY which references its own PRIMARY KEY, like this:
|---------------------|------------------|------------------|
| ID | NAME | PARENT_ID |
|---------------------|------------------|------------------|
| 01 | John | 04 |
|---------------------|------------------|------------------|
| 02 | Paul | 01 |
|---------------------|------------------|------------------|
| 03 | George | 02 |
|---------------------|------------------|------------------|
| 04 | Ringo | 03 |
|---------------------|------------------|------------------|
Problem:
So as you see there is looped hierarchy: Ringo->George->Paul->John->Ringo->George->Paul->John->etc.
Question:
Whether there is a SQL select that can detect such loops?
I know that I can write recursive PL/SQL procedure but I prefer solution with "pure" SQL.
Thank you in advance