WMSYS.WM_CONCAT 函式的用法 ZT
WMSYS.WM_CONCAT 函式的用法[@more@]
SQL> select version from v$instance;
VERSION
-----------------
10.2.0.1.0
SQL>
SQL> create table IDTABLE
2 (
3 id number,
4 val varchar2(20)
5 )
6 ;
Table created
SQL>
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'abc');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'abc');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'def');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'def');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'ghi');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'jkl');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'mno');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'mno');
1 row inserted
SQL> select id,val from idtable;
ID VAL
---------- --------------------
10 abc
10 abc
10 def
10 def
20 ghi
20 jkl
20 mno
20 mno
8 rows selected
SQL> commit;
Commit complete
SQL>
SQL> SELECT ID, WMSYS.WM_CONCAT(VAL) AS ENAMES
2 FROM IDTABLE
3 GROUP BY ID;
ID ENAMES
---------- --------------------------------------------------------------------------------
10 abc,abc,def,def
20 ghi,jkl,mno,mno
SQL>
SQL> SELECT ID, WMSYS.WM_CONCAT(DISTINCT VAL) AS ENAMES
2 FROM IDTABLE
3 GROUP BY ID
4 ORDER BY ID;
ID ENAMES
---------- --------------------------------------------------------------------------------
10 abc,def
20 ghi,jkl,mno
SQL>
SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(PARTITION BY ID) AS ENAMES
2 FROM IDTABLE
3 ORDER BY ID;
ID VAL ENAMES
---------- -------------------- --------------------------------------------------------------------------------
10 abc abc,abc,def,def
10 abc abc,abc,def,def
10 def abc,abc,def,def
10 def abc,abc,def,def
20 ghi ghi,jkl,mno,mno
20 jkl ghi,jkl,mno,mno
20 mno ghi,jkl,mno,mno
20 mno ghi,jkl,mno,mno
8 rows selected
SQL>
SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(ORDER BY ID, VAL) AS ENAMES
2 FROM IDTABLE
3 ORDER BY ID;
ID VAL ENAMES
---------- -------------------- --------------------------------------------------------------------------------
10 abc abc,abc
10 abc abc,abc
10 def abc,abc,def,def
10 def abc,abc,def,def
20 ghi abc,abc,def,def,ghi
20 jkl abc,abc,def,def,ghi,jkl
20 mno abc,abc,def,def,ghi,jkl,mno,mno
20 mno abc,abc,def,def,ghi,jkl,mno,mno
VERSION
-----------------
10.2.0.1.0
SQL>
SQL> create table IDTABLE
2 (
3 id number,
4 val varchar2(20)
5 )
6 ;
Table created
SQL>
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'abc');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'abc');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'def');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (10, 'def');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'ghi');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'jkl');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'mno');
1 row inserted
SQL> insert into IDTABLE (ID, VAL)
2 values (20, 'mno');
1 row inserted
SQL> select id,val from idtable;
ID VAL
---------- --------------------
10 abc
10 abc
10 def
10 def
20 ghi
20 jkl
20 mno
20 mno
8 rows selected
SQL> commit;
Commit complete
SQL>
SQL> SELECT ID, WMSYS.WM_CONCAT(VAL) AS ENAMES
2 FROM IDTABLE
3 GROUP BY ID;
ID ENAMES
---------- --------------------------------------------------------------------------------
10 abc,abc,def,def
20 ghi,jkl,mno,mno
SQL>
SQL> SELECT ID, WMSYS.WM_CONCAT(DISTINCT VAL) AS ENAMES
2 FROM IDTABLE
3 GROUP BY ID
4 ORDER BY ID;
ID ENAMES
---------- --------------------------------------------------------------------------------
10 abc,def
20 ghi,jkl,mno
SQL>
SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(PARTITION BY ID) AS ENAMES
2 FROM IDTABLE
3 ORDER BY ID;
ID VAL ENAMES
---------- -------------------- --------------------------------------------------------------------------------
10 abc abc,abc,def,def
10 abc abc,abc,def,def
10 def abc,abc,def,def
10 def abc,abc,def,def
20 ghi ghi,jkl,mno,mno
20 jkl ghi,jkl,mno,mno
20 mno ghi,jkl,mno,mno
20 mno ghi,jkl,mno,mno
8 rows selected
SQL>
SQL> SELECT ID, VAL, WMSYS.WM_CONCAT(VAL) OVER(ORDER BY ID, VAL) AS ENAMES
2 FROM IDTABLE
3 ORDER BY ID;
ID VAL ENAMES
---------- -------------------- --------------------------------------------------------------------------------
10 abc abc,abc
10 abc abc,abc
10 def abc,abc,def,def
10 def abc,abc,def,def
20 ghi abc,abc,def,def,ghi
20 jkl abc,abc,def,def,ghi,jkl
20 mno abc,abc,def,def,ghi,jkl,mno,mno
20 mno abc,abc,def,def,ghi,jkl,mno,mno
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82387/viewspace-1023053/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- wmsys.wm_concat 函式用法函式
- SYS_CONTEXT函式的用法(ZT)Context函式
- oracle 12C wmsys.wm_concat()函式Oracle函式
- ascii函式和substr函式的用法ASCII函式
- GetModuleFileName函式的用法函式
- createStyleSheet()函式的用法函式
- qsort函式的用法函式
- COALESCE函式的用法。函式
- SQLSERVER日期函式(zt)SQLServer函式
- Instr函式的用法函式
- 【Oracle的NVL函式用法】Oracle函式
- fork()函式的基本用法函式
- Oracle dump函式的用法Oracle函式
- openat()函式的用法示例函式
- Oracle trunc()函式的用法Oracle函式
- Oracle 函式 Translate 的用法Oracle函式
- oracle的with函式用法示例Oracle函式
- Translate函式用法函式
- abs函式用法函式
- C語言中函式printf()和函式scanf()的用法C語言函式
- Oracle - 分組連線欄位函式WMSYS.WM_CONCAT的使用Oracle函式
- C++ 函式 realloc 的用法C++函式
- PostgreSQL>視窗函式的用法SQL函式
- string 函式的基本用法函式
- Excel函式的初級用法Excel函式
- mysql中replace函式的用法MySql函式
- Oracle to_date()函式的用法Oracle函式
- translate函式的靈活用法函式
- cast函式的用法案例AST函式
- 關於lag函式的用法函式
- SQL LEN()函式用法SQL函式
- SSD-函式用法函式
- OVER(PARTITION BY)函式用法函式
- oracle table()函式用法Oracle函式
- 【轉】oracle的substr函式的用法Oracle函式
- StretchBlt函式和BitBlt函式的區別和用法函式
- 【ORACLE12C】oracle 12C wmsys.wm_concat()函式Oracle函式
- C — 快排函式 qsort 的用法函式