Home > database > An oracle database table field in the saved id, and with a comma, id corresponding to the detailed i
An oracle database table field in the saved id, and with a comma, id corresponding to the detailed i
Time:10-19
I saw a similar problem, no answer not Oracle
Now there are two table, table in a
Aid manager 1, 1, 2, 3 2, 2, 4
In table b
The bid name 1 the li 2. liu3 threes 4 li si
How to joint query out The serial number manager manager name 1 1, 2, 3 li, liu, zhang SAN 2 2, 2, liu li si
Help!!!!!!!!!!
CodePudding user response:
With a as (select '1' aid, '1, 2, 3' manager from dual union all select '2', '2, 4' from dual), B the as (select '1' bid, 'li' name from dual union all select '2', 'liu 2 from dual union all Select '3', 'zhang' from dual union all select '4', 'bill' from dual),
Aa as (select aid, regexp_substr (competent leadership, '[^,]', 1, level) manager From a Connect by level<=regexp_count (competent leadership, ', ') + 1 And the prior aid=aid And the prior sys_guid () is not null), Ab as (select aa. Aid, aa. Competent leadership, b. name The from aa, b Where aa. Manager=b.b id)
Select aid, listagg (manager, ', ') within group (order by competent leadership) competent leadership, Listagg (name, ', ') within group (order by competent leadership) name The from ab Group by aid
CodePudding user response:
Select aid, the competent leadership, (select listagg (b. name, ', ') within group (the order by the bid) The from b Where instr (', '| | a. manager | |', ', ', '| | b.b id | |', ') & gt; 0) manager's name From a
CodePudding user response:
To learn, you can also write so
CodePudding user response:
Performance is the best way is to write a function, according to the comma will id find them into one name spliced back to Stitching order also won't have what problem