Попробуйте как есть:
WITH
TAB1 (Username, Group) AS
(VALUES
('GPARR11', 'ACC-ADMIN')
, ('LPARR11', 'PRT-MGR ')
, ('CSMITH ', 'VP-SALES ')
)
, TAB2 (Group, Ref, Switches) AS
(
VALUES
('ACC-ADMIN', 500, 'YNYNNNYN')
, ('ACC-ADMIN', 502, 'YNYYY')
, ('ACC-ADMIN', 503, 'NYNYYN')
, ('PRT-MGR ', 500, 'NNNYNNNYN')
, ('PRT-MGR ', 633, 'YNYNNNYNNY')
, ('VP-SALES ', 500, 'NYNYNNNYNY')
, ('VP-SALES ', 999, 'NYNYNYNYNYNNYNNYNYNN')
)
, TAB3 (Ref, Sequence, Permission) AS
(
VALUES
(500, 1, 'Access G&B ')
, (500, 2, 'Access Call ')
, (500, 3, 'Access A/R ')
, (633, 1, 'Modify G&B ')
, (633, 2, 'Modify Call ')
, (633, 3, 'Modify Memos')
, (999, 1, 'Delete G&B ')
)
SELECT
CASE WHEN ROWNUMBER() OVER (PARTITION BY T1.Username, T2.Group ORDER BY T3.Sequence) = 1 THEN T1.Username ELSE '' END Username
, CASE WHEN ROWNUMBER() OVER (PARTITION BY T1.Username, T2.Group ORDER BY T3.Sequence) = 1 THEN T2.Group ELSE '' END Group
, T3.Permission, DECODE(T.Flag, 'Y', 'TRUE', 'FALSE') Enabled
FROM TAB1 T1
JOIN TAB2 T2 ON T2.Group = T1.Group
CROSS JOIN xmltable
(
'let $n := substring(replace($s, "(.)", " $1"), 2) for $id in tokenize($n, " ") return <i>{string($id)}</i>'
passing
t2.switches as "s"
columns
seq for ordinality
, flag char(1) path '.'
) T
JOIN TAB3 T3 ON T3.Ref = T2.Ref AND T3.Sequence = T.Seq
ORDER BY T1.Username, T2.Group, T3.Sequence;
Результат:
|USERNAME|GROUP |PERMISSION |ENABLED|
|--------|---------|------------|-------|
|CSMITH |VP-SALES |Access G&B |FALSE |
| | |Delete G&B |FALSE |
| | |Access Call |TRUE |
| | |Access A/R |FALSE |
|GPARR11 |ACC-ADMIN|Access G&B |TRUE |
| | |Access Call |FALSE |
| | |Access A/R |TRUE |
|LPARR11 |PRT-MGR |Access G&B |FALSE |
| | |Modify G&B |TRUE |
| | |Access Call |FALSE |
| | |Modify Call |FALSE |
| | |Access A/R |FALSE |
| | |Modify Memos|TRUE |
ссылка dbfiddle .