Tuesday, October 26, 2010

Nifty way (in Oracle) to get comma-separated list

There's a LISTAGG function (11g only?) that will let you create a comma-delimited list.

select LISTAGG(t.item_id, ',') WITHIN GROUP( ORDER BY t.style_id) FROM (select distinct i.item_id as item_id FROM purchase_order_item poi JOIN item i ON i.item_id = poi.item_id WHERE poi.po_id = 12345) t