如何将多个oracle行合并为一行?

如何将多个oracle行合并为一行?,oracle,Oracle,在这种oracle情况下,如何在单个查询中获得以下结果 Table 1 Customer | Order_Number 1 1 1 2 2 1 Table 2 Customer | Order_Number | Employee | Tag 1 1 Bob on hold 1 1 Larry shipped 1

在这种oracle情况下,如何在单个查询中获得以下结果

Table 1
Customer | Order_Number  
1          1
1          2 
2          1 

Table 2 
Customer | Order_Number  | Employee | Tag
1            1             Bob        on hold
1            1             Larry      shipped
1            2             Larry      shipped

Results
Customer   | Order_Number   | Tags
1              1               Bob - on hold; Larry - shipped
1              2               Larry - shipped;
2              1               (Empty or null) 
我在把标签作为一个字符串返回时被绊倒了

你需要你的帮助


如果您的Oracle版本足够旧,则可以将其替换为或。

您没有提到您的
DB版本。所以答案完全取决于你使用的版本

如果您在
11g
及以上,请使用
listag

但是,如果您在
pre 11g
release上,则您有以下选项:

  • Oracle 9i中的行编号()和系统连接路径函数
  • Oracle 10g中的收集功能
  • STRAGGTom Kyte在此建议的函数
  • 注:绝不在生产系统中使用
    WM_CONCAT
    ,未记录。只需向Oracle支持部门提交一份SR,并说您使用了它,然后查看响应。而且它不存在于
    12c

    此处的更多示例

    切勿在生产系统中使用
    WM_CONCAT
    ,因为它是未记录的。只需向Oracle支持部门提交一份SR,并说您使用了它,然后查看响应。而且它不存在于
    12c
    中。