これがOracle9iソリューションです。このジョブは、クエリでCONNECTBY句を必要とするSYS_CONNECT_BY_PATH関数を使用して実行されます。何かによって行を接続するために、VEHICLEテーブルは「準備」されています...それはcurrとprevの行番号で埋められます。
SELECT
vc.vehicle_class_name,
RTRIM(REPLACE(MAX(SYS_CONNECT_BY_PATH(v.completed,'|')) KEEP (DENSE_RANK LAST ORDER BY v.curr),'|',''),',') completed,
RTRIM(REPLACE(MAX(SYS_CONNECT_BY_PATH(v.incomplete,'|')) KEEP (DENSE_RANK LAST ORDER BY v.curr),'|',''),',') incomplete
FROM
(SELECT
vehicle_class_id,
CASE WHEN status=2 THEN vehicle_id||',' END completed,
CASE WHEN status<>2 THEN vehicle_id||',' END incomplete,
ROW_NUMBER() OVER (PARTITION BY vehicle_class_id ORDER BY vehicle_id) curr,
ROW_NUMBER() OVER (PARTITION BY vehicle_class_id ORDER BY vehicle_id)-1 prev
FROM
vehicle) v JOIN vehicle_class vc
ON v.vehicle_class_id=vc.vehicle_class_id
GROUP BY
vc.vehicle_class_name
CONNECT BY
v.prev=PRIOR v.curr AND v.vehicle_class_id=PRIOR v.vehicle_class_id
START WITH
v.curr=1;