我正在查找可以從多個表中取多個字段並將它們合併到一個字段中的查詢。防爆。我有一個查詢,看起來像:Oracle - 從多個表到多個表的多行
select to_char(a.comments), to_char(b.comments), to_char(c.comments)
from crm.custprob a
left join crm.custcall b on b.servno = a.servno
left join crm.custlog c on c.servno = b.servno
where a.servno = 1716942
,併產生輸出:
a.comments b.comments c.comments 1 Regular 3 Primary 5 Log 1 Regular 3 Primary 4 Log 1 Regular 2 Other 5 Log 1 Regular 2 Other 4 Log
我想是會產生所有在一行輸出的查詢,並在一個領域(我不關心數字的順序),所以它看起來像:
Comments 1 Regular 2 Other 3 Primary 4 Log 5 Log
使用'''opoerator(在你的select中替換逗號與||)或嵌套'concat',因爲函數只支持2個字符串,所以你必須嵌套一個concat。 – xQbert
儘管替換逗號仍然返回4行,但如果可能的話,我想將它降到1行 –
ahh那麼根據您使用的oracle版本,您需要'wm_concat()'或'ListAgg()'。 – xQbert