select 
  a.orderid,
  a.ordertype,
  carno=stuff((select ','+ltrim(b.carno) from order_car where orderid=b.orderid),1,1,'') 
from
  [order] a
join
  order_car b
on
  a.orderid=b.orderid
group by
  a.orderid,
  a.ordertype上面的MSSQL语句在oracle 中怎么写

解决方案 »

  1.   

    select 
      a.orderid, 
      a.ordertype, 
      (select ltrim(b.carno) from order_car where orderid=b.orderid) carno 
    from 
      "order" a 
    join 
      order_car b 
    on 
      a.orderid=b.orderid 
    group by 
      a.orderid, 
      a.ordertype 看看对不对
    不知为什么要在ltrim(b.carno) 前加个',',然后再用stuff去掉
      

  2.   

    我在PL/SQL中改为 如下:但是报错为:stuff标识符无效select 
      a.entrunstno,
      stuff((select ','+ltrim(vechicleid) from tbt_asn_zhuanche where entrunstno =b.entrunstno ),1,1,'') as carnm
    from
      tbt_ent_information a,  tbt_asn_zhuanche b
    where   a.entrunstno =b.entrunstno
      

  3.   

    select 
      a.orderid, 
      a.ordertype, 
      b.carno
    from 
      "order" a 
    join 
      order_car b 
    on 
      a.orderid=b.orderid 
    group by 
      a.orderid, 
      a.ordertype 看起来这样也一样了
      

  4.   

    应该是这个意思吧select 
      a.orderid, 
      a.ordertype, 
      wm_concat(b.carno) carno 
    from 
      "order" a 
    join 
      order_car b 
    on 
      a.orderid=b.orderid 
    group by 
      a.orderid, 
      a.ordertype 
      

  5.   

    stuff()是MSSQL里的
    看你的意思可以这样写,试试
    substr((select ','+ltrim(vechicleid) from tbt_asn_zhuanche where entrunstno =b.entrunstno ),1,1)  carnm 
      

  6.   

    谢谢楼上,我不会oracle 的。
    是想把子表的一个字段的多行拼成一个字段的。wm_concat好像可以解决这个问题
      

  7.   

    wm_concat就是为了实现这个功能产生的
    你测试下,10g以上的支持
      

  8.   

    提醒下
    在oracle中字符串拼接不要用+,改成||