Oracle 10g: wm_concat
Oracle 11g新增了函數:
LISTAGG
簡單例子:
SELECT a.id, wm_concat (a.remark) new_result FROM tb_name a group by a.id
可以配合over一起使用,具體復雜的用法可以到時再查
通用SQL:
在使用過程中發現有些oracle會存在查詢不出數據的問題,這個無解,所以找了個純sql的列轉行
SELECT feeapportion_id, SUBSTR(MAX(SYS_CONNECT_BY_PATH(contract_no, ',')), 2) contract_no FROM (SELECT feeapportion_id, contract_no, rn, LEAD(rn) OVER(PARTITION BY feeapportion_id ORDER BY rn) rn1 FROM (SELECT feeapportion_id, contract_no, ROW_NUMBER() OVER(ORDER BY contract_no) rn FROM TH_SF_FEEAPPORTION_d)) START WITH rn1 IS NULL CONNECT BY rn1 = PRIOR rn GROUP BY feeapportion_id