Я думаю, вы слишком усложняете это, и вам просто нужна базовая операция отмены:
select account_id as "AccountNumber", position as "Order", value as "Value"
from (
select 1 as facility_id, hl.account_id, tdl.dx_one_id, tdl.dx_two_id,
tdl.dx_three_id, tdl.dx_four_id, tdl.dx_five_id, tdl.dx_six_id
from account_list hl
inner join transactions tdl on hl.account_id = tdl.account_id
)
unpivot (value for position in (dx_one_id as 1, dx_two_id as 2, dx_three_id as 3,
dx_four_id as 4, dx_five_id as 5, dx_six_id as 6))
Демо с начальными данными, соответствующими вашему первому примеру:
-- CTEs for sample data
with account_list (account_id) as (
select 1 from dual
union all select 2 from dual
union all select 3 from dual
),
transactions (account_id, dx_one_id, dx_two_id, dx_three_id, dx_four_id, dx_five_id, dx_six_id) as (
select 1, 123, 1234, 12345, 12, 12345, 1234 from dual
union all select 2, 123, 1234, 12345, 12, 12345, 1234 from dual
union all select 3, 123, 1234, 12345, 12, 12345, 1234 from dual
)
-- actual query
select account_id as "AccountNumber", position as "Order", value as "Value"
from (
select 1 as facility_id, hl.account_id, tdl.dx_one_id, tdl.dx_two_id,
tdl.dx_three_id, tdl.dx_four_id, tdl.dx_five_id, tdl.dx_six_id
from account_list hl
inner join transactions tdl on hl.account_id = tdl.account_id
)
unpivot (value for position in (dx_one_id as 1, dx_two_id as 2, dx_three_id as 3,
dx_four_id as 4, dx_five_id as 5, dx_six_id as 6))
order by facility_id, account_id, position;
, который получает
AccountNumber Order Value
------------- ---------- ----------
1 1 123
1 2 1234
1 3 12345
1 4 12
1 5 12345
1 6 1234
2 1 123
2 2 1234
2 3 12345
2 4 12
2 5 12345
2 6 1234
3 1 123
3 2 1234
3 3 12345
3 4 12
3 5 12345
3 6 1234
18 rows selected.