循环查询sql带逗号(,)分隔的数据 以及一对多数据转化为逗号(,)分割数据...
生活随笔
收集整理的這篇文章主要介紹了
循环查询sql带逗号(,)分隔的数据 以及一对多数据转化为逗号(,)分割数据...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
逗號分割數據轉化為一對多數據
select * from sys_role_list where id in(select c from(with test as (select roleid c from sys_role_info where id=1)select substr(t.ca,instr(t.ca, ',', 1, c.lv) + 1,instr(t.ca, ',', 1, c.lv + 1) - (instr(t.ca, ',', 1, c.lv) + 1)) AS cfrom (select ',' || c || ',' AS ca,length(c || ',') - nvl(length(REPLACE(c, ',')), 0) AS cnt FROM test) t,(select LEVEL lv from dual CONNECT BY LEVEL <= 100) c where c.lv <= t.cnt ))
select * from sys_role_list where id in(select c from(with test as (select roleid c from sys_role_info where id=1)select substr(t.ca,instr(t.ca, ',', 1, c.lv) + 1,instr(t.ca, ',', 1, c.lv + 1) - (instr(t.ca, ',', 1, c.lv) + 1)) AS cfrom (select ',' || c || ',' AS ca,length(c || ',') - nvl(length(REPLACE(c, ',')), 0) AS cnt FROM test) t,(select LEVEL lv from dual CONNECT BY LEVEL <= 100) c where c.lv <= t.cnt ))
轉化為逗號分割數據
(select DoctID, deptname = (stuff((select ',' + deptname from HE_DoctDeptRelation inner join yb_deptdict on yb_deptdict.DeptID=HE_DoctDeptRelation.DeptID where DoctID = a.DoctID for xml path('')),1,1,'')) from HE_DoctDeptRelation a group by DoctID) as DoctDept?
轉載于:https://www.cnblogs.com/Iyce/p/3700987.html
總結
以上是生活随笔為你收集整理的循环查询sql带逗号(,)分隔的数据 以及一对多数据转化为逗号(,)分割数据...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Mysql】MySQL与Oracle的
- 下一篇: define宏定义中的#,##,@#及\