копосов нв |
необходимо описать условие вывода значения для поля f_activity. Если у родителя значение f_activity = 0 тогда значение поля f_activity для всех дочерних тоже 0.
|
with t as (select 1 id, 10 value, null id_parent from dual union all
select 2 id, 20 value, 1 id_parent from dual union all
select 3 id, 0 value, 1 id_parent from dual union all
select 4 id, 40 value, 2 id_parent from dual union all
select 5 id, 50 value, 3 id_parent from dual union all
select 6 id, 60 value, 3 id_parent from dual union all
select 7 id, 70 value, 5 id_parent from dual union all
select 8 id, 80 value, 2 id_parent from dual union all
select 9 id, 90 value, 7 id_parent from dual)
--
select id,
id_parent,
value,
lev,
case when decode(pos, -1, lev, pos) < lev
then 0
else value
end value_new
from (select id, value,
instr(translate(replace(sys_connect_by_path(value, ','),',0,',',x,'),' 1234567890 ',' '),'x') - 1 pos,
id_parent,
level lev
from t
start with id_parent is null
connect by id_parent = prior id)