江清风
2017-05-23 01:47
采纳率: 0%
浏览 1.7k

oracle数据库中,要求不能用wm_concat函数合并值

问题:oracle数据库中,要求不能用wm_concat函数,合并值,希望得到结果如下:
s_type s2
水果 葡萄,哈密瓜,香瓜,火龙果
蔬菜 西兰花,茼蒿,茄子
坚果 核桃,巴旦木

数据如下:
create table t_thz_1(
n_id number(10),
s_mc varchar2(100),
s_type varchar2(10)
);

truncate table t_thz_1;
insert into t_thz_1(n_id,s_mc,s_type)
select 1 n_id,'葡萄' s_mc,'水果' s_type from dual union all
select 2 n_id,'哈密瓜' s_mc,'水果' s_type from dual union all
select 3 n_id,'西兰花' s_mc,'蔬菜' s_type from dual union all
select 4 n_id,'核桃' s_mc,'坚果' s_type from dual union all
select 5 n_id,'茼蒿' s_mc,'蔬菜' s_type from dual union all
select 6 n_id,'香瓜' s_mc,'水果' s_type from dual union all
select 7 n_id,'巴旦木' s_mc,'坚果' s_type from dual union all
select 8 n_id,'茄子' s_mc,'蔬菜' s_type from dual union all
select 10 n_id,'火龙果' s_mc,'水果' s_type from dual
;
commit;

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • wangwx0824 2017-05-23 06:30

    select s_type,wm_concat(s_mc) as s_mc from t_thz_1 group by s_type,s_type

    打赏 评论
  • wangwx0824 2017-05-24 06:14

    O.O 不好意思 select s_type,LISTAGG(s_mc,',') within GROUP (order by s_type) from t_thz_1 group by s_type

    打赏 评论

相关推荐 更多相似问题