代码一:
select c.ci_id, wm_concat(s.stu_name) stu_ids from pm_ci c, pm_stu s where instr(c.stu_ids, s.stu_id) > 0 group by c.ci_id;
代码实现结果如下:
发现和视频结果不一样,没有按序号顺序输入,可能是因为wm_concat()没有排序功能?这点不清楚,请大佬指教!!
利用listagg()代替wm_concat()就可以输出正确结果了。
代码二:
select c.ci_id, listagg(s.stu_name, ',') within group (order by s.stu_id) stu_ids from pm_ci c, pm_stu s where instr(c.stu_ids, s.stu_id) > 0 group by c.ci_id;
结果如下:
select ci.ci_id ci_id, listagg(stu.stu_name,',') stu_name
from pm_ci ci,pm_stu stu
where instr(ci.stu_ids,stu.stu_id) > 0
group by ci.ci_id
order by ci.ci_id