17,140
社区成员




SQL> select * from emp;
ID NAME
---------- ----------
2 李四
1 张三
SQL> select * from org;
ID NAME
---------- ----------
1 部门1
2 部门2
3 部门3
4 部门4
SQL> select * from emp_org;
EMPID ORGID
---------- --------------------------------------------------------------------------------
1 1,3,4
2 1,2,3,4
SQL>
SQL> select emp.name, emp.id, org.id, org.name
2 from emp, org
3 where org.id in
4 (select TRIM(REGEXP_SUBSTR(orgid, '[^,]+', 1, level)) value
5 from emp_org
6 where empid = emp.id
7 connect by level <= length(regexp_replace(orgid, '[^,]*')) + 1)
8 ;
NAME ID ID NAME
---------- ---------- ---------- ----------
李四 2 1 部门1
李四 2 2 部门2
李四 2 3 部门3
李四 2 4 部门4
张三 1 1 部门1
张三 1 3 部门3
张三 1 4 部门4
7 rows selected
SQL>