Why does Oracle pseudo column CONNECT_BY_ISLEAF seems broken? Why does Oracle pseudo column CONNECT_BY_ISLEAF seems broken? oracle oracle

Why does Oracle pseudo column CONNECT_BY_ISLEAF seems broken?


I didn't take the time to fully understand your data model and would suggest that you might have difficulty accomplishing your goal in an understandable manner without some sort of primary key in your table. CONNECT BY is one of the more advanced query forms in Oracle and having a traditional PRIOR t.id = t.parent_id relationship makes it easier.

Anyway, the reason for the results that you find confusing is because you have this row in your data:

into TEST_HISTORY values (88888, 3, 'U', null)

It is a "child" of the row you think is a leaf, making that row actually not a leaf at all.

Run your query without the WHERE clause and you should see it. The CONNECT BY happens before the WHERE clause. Filtering out leaves in the WHERE clause does not make their now-childless parents into leaves.