說明1:想把查詢出來的多列資料合併成一列(combine multiple rows into one row),該如何做?
做法:使用LISTAGG函式,語法:LISTAGG(column[, 'delimiter']) WITHIN GROUP (ORDER BY column),例:
SELECT LISTAGG(ITEM, ';') WITHIN GROUP (ORDER BY No) DISPLAY
FROM table;
參考資料:
//http://stackoverflow.com/questions/1076011/how-can-multiple-rows-be-concatenated-into-one-in-oracle-without-creating-a-stor
說明2:去除查詢資料的特定字元TRIM/LTRIM/RTRIM
語法:L(R)TRIM( string, [ trim_string ] );
TRIM( [ [ LEADING | TRAILING | BOTH ] trim_character FROM ] string )
例:
--remove . on the right side of DISPLAY
SELECT RTRIM(DISPLAY, '.')DISPLAY
FROM table
參考資料:
http://www.techonthenet.com/oracle/functions/trim.php
http://give.pixnet.net/blog/post/25491792-(%E8%BD%89%E8%BC%89)-oracle%E7%9A%84%E5%AD%97%E4%B8%B2%E8%99%95%E7%90%86
沒有留言:
張貼留言