1

我有一个名为 Dummy 的表,如下所示:

No.   Name
1     ABC
2     NMD
2     SDSDS
1     23ererer

现在我想Name用给定的数字连接所有列

例如。说不。1我想ABC23ererer作为我的输出吗

这将在 ORACLE(SQL) 中完成,而不使用 PL-SQL。

如何才能做到这一点?

4

4 回答 4

1

这可能会有所帮助...

select NO,
  listagg(NAME, ',') within group (order by NAME) as name
from TableName
group by NO

或者检查这个

于 2013-07-04T05:37:32.557 回答
1

oracle10g 不支持 LISTAGG。如果您有 10g,我认为以下查询将对您有所帮助。

select No, rtrim(Name,',') Name
       from ( select No
      , Name, rn
         from yourtable
               model
                      partition by (No)
                        dimension by (row_number() over
                                     (partition by No order by Name) rn
                                    )
                       measures     (cast(Name as varchar2(40)) Name)
                       rules
                       ( Name[any] order by rn desc = Name[cv()]||''||Name[cv()+1]
                       )
              )
        where rn = 1
        order by NO

在 sql fiddle 中查看您的演示

于 2013-07-04T05:38:49.060 回答
0
SELECT "No.", LISTAGG(Name, ',') WITHIN GROUP (ORDER BY "No.") AS Name
FROM TableName
GROUP BY "No.";
于 2013-07-04T05:40:24.563 回答
-4

尝试这个 :

选择号码+' '+
名称 FROM table_name

于 2013-07-04T05:38:11.893 回答