SQL> create table y ( id_emp number , name varchar2(2) ) ;
Table created.
SQL> insert into y values ( 101 , 'A' ) ;
1 row created.
SQL> insert into y values ( 104, 'B' ) ;
1 row created.
SQL> insert into y values ( 103 , 'C' ) ;
1 row created.
SQL> commit ;
Commit complete.
SQL> select * from t ;
ID VAL
---------- -------------
1111 101,104,103
SQL> select * from y ;
ID_EMP NAME
---------- ----
101 A
104 B
103 C
SQL> with emps as ( SELECT regexp_substr(val, '[^,]+', 1, LEVEL) as empid FROM t
2 CONNECT BY regexp_substr(val, '[^,]+', 1, LEVEL) IS NOT NULL )
3 select y.name , emps.empid from y inner join emps on ( y.id_emp = emps.empid ) ;
NAME EMPID
---- -----------------------------
A 101
B 104
C 103
with t as (
select org_id
,employees txt
from team_emp_map
where org_id = 1111
)
,emp as ( -- split string into records
select org_id
,regexp_substr(t.txt, '\d+', 1, level) emp_id
from t
connect by regexp_substr(t.txt, '\d+', 1, level) is not null
)
select emp.org_id
,employee.emp_nm
from emp
,employee
where emp.emp_id = employee.emp_id
4条答案
按热度按时间bcs8qyzn1#
一种选择是使用运算符
LIKE
在ON
表连接的子句,如下所示:看他演示。
结果:
ukxgm1gy2#
好的,我明白了,你需要用正确的多对多关联来修复你的team\u emp\u map表。
在这种情况下,我想您可以使用regex(regexp\u substr)来拆分逗号分隔的列。看看这篇文章吧。
8ljdwjyq3#
一种方法是使用regexp\u substr和connect level by拆分第二个表的数组中的内容。
我举个例子:
koaltpgm4#