Oracle中wm_concat()的使用方法

时间:2022-05-16 02:47:38

以下两种方式使用wm_concat()的使用方法是等效的。

方法一:使用窗口函数,wm_concat支持窗口函数

select distinct classKey,className, classOrder, weekDayKey, lessonkey, lessonName, lessonType,
wm_concat(subjectkey) over(partition by classKey,className, classOrder, weekDaykey, lessonkey, lessonName,lessonType),
wm_concat(subjectName) over(partition by classKey,className, classOrder, weekDaykey, lessonkey, lessonName,lessonType)
from VW_CLASSCourseTable
Where schoolKey = P_SchoolKey
And gradeKey = P_GradeKey
And termKey = P_TermKey
order by classOrder asc, weekDaykey asc, lessonType asc

方法二:使用group by方式

select classKey,className, classOrder, weekDaykey, lessonkey, lessonName, lessonType,
wm_concat(subjectkey),
wm_concat(subjectName)
from VW_CLASSCourseTable
Where schoolKey = P_SchoolKey
And gradeKey = P_GradeKey
And termKey = P_TermKey
group by classKey,className, classOrder, weekDaykey, lessonkey, lessonName,lessonType
order by classOrder asc, weekDaykey asc, lessonType asc ;