专注数据库开发管理
分类: Oracle
2012-10-27 10:01:17
10g列改行函数wmsys.wm_concat:
-- 列改行
SQL> select replace(wmsys.wm_concat(table_name),',','*') from all_tables where rownum<=5;
REPLACE(WMSYS.WM_CONCAT(TABLE_
--------------------------------------------------------------------------------
ICOL$*IND$*COL$*CLU$*TAB$
11g中可用listagg,比10g的强大多了。
select listagg(id) within group(order by id) from t;
-- 换行
SQL> select 'abc'||chr(13)||'def'||chr(13)||'ghi' from dual;
'ABC'||CHR(13)||'DEF'||CHR(13)
------------------------------
abc
def
ghi
-- 显示小数整数为0时
SQL> select to_char(.0129,'fm9999990.9999') from dual;
TO_CHAR(.0129,'FM9999990.9999'
------------------------------
0.0129
不过需注意的是:listagg返回的是varchar型,而wmsys.wm_concat返回的是clob数据类型。
-- The End --