多列转字符串拼接
select id||username str from dual
字符串拆分方式: substr、instr、regexp_substr函数方式
行转列 wm_concat函数
select wm_concat(name) name from dual;
SELECT to_char(wm_concat(decode(I.NAME, null, '', I.NAME || ': ') ||
decode(I2.NAME, null, '', I2.NAME || ': ') ||
decode(V.VALUE, null, '', 'Y', '√', V.VALUE))) favarite
FROM CUST_BASE_INFO C
行转列 ,默认逗号隔开
Oracle 11g 行列互换 pivot 和 unpivot 说明
在Oracle 11g中,Oracle 又增加了2个查询:pivot(行转列) 和unpivot(列转行)
pivot 列转行
pivot(聚合函数 for 列名 in(类型)) ,其中 in('') 中可以指定别名,in中还可以指定子查询
unpivot 行转列
与pivot类似; unpivot没有聚合函数,执行速度效率也没有前者高