Itβs kind of black magic, but you can use table-cast-multiset to refer to one table from another in the WHERE clause:
create table t1( usr number, parent number ); create table t2( usr number, perm char(1) ); insert into t1 values (1,null); insert into t1 values (2,1); insert into t1 values (3,1); insert into t1 values (4,3); insert into t2 values (1,'A'); insert into t2 values (3,'B'); select t1.usr , t2.perm from t1 , table(cast(multiset( select t.usr from t1 t connect by t.usr = prior t.parent start with t.usr = t1.usr ) as sys.odcinumberlist)) x , t2 where t2.usr = x.column_value ;
In subquery x I create a table of all parents for a given user from t1 (including myself), and then attach it to the permissions for these parents.
source share