日期:2014-05-17  浏览次数:20812 次

怎样将字段中存的字符串拼接成特定格式的字符串
现有表A,其中表A的结构如下
id     code    name 
1      A       语文
2      B       数学
3      C       英语

表B的结构如下
product_id      product_code   
1               A,B
2               A
3               A,B,C

我现在想要查询表B的数据,并且把product_code转换成对应的中文,如
1      语文,数学
2      语文
3      语文,数学,英语

我的sql是这样的:
select B.id,( select to_char(wm_concat( name  )) as menu_name from A where id in 
( select product_code from B where id =B.id )  ) as menu_name from B  B
这样只有当product_code为A的时候才正确显示,求指导
oracle?字符串?转换

------解决方案--------------------
这个是完全手动拼接出来的
SCOTT@xp-ora10g> select * from A;

        ID CODE  NAME
---------- ----- ----------
         1 A     语文
         2 B     数学
         3 C     英语

SCOTT@xp-ora10g> select * from B;

PRODUCT_ID PRODUCT_CO
---------- ----------
         1 A,B
         2 A
         3 A,B,C

SCOTT@xp-ora10g> select product_id,product_code,decode(product_code,
  2  'A,B','语文,数学',
  3  'A','语文',