Вы можете использовать decode
с aggregation
, используя regex
для динамического извлечения цифры из code
столбца
with excluded(ctr_nmbr, code, exec_id ) as
(
select 'E0105753', '2_EXEC_ZERO', 565 from dual union all
select 'E0105753', '3_EXEC_MAT', 565 from dual
)
select ctr_nmbr, exec_id,
max(decode(code,'2_EXEC_ZERO',regexp_substr(code,'[^_]+',1),null)) as Exclude_Zero,
max(decode(code,'3_EXEC_MAT',regexp_substr(code,'[^_]+',1),null)) as Exclude_Mat
from excluded
group by ctr_nmbr, exec_id;
Демо