sql - Comma separated column without XML path -


i have table below

id name 1  1  b 1  c 2  d 2  e 3  f 

i result as

id name 1  a,b,c 2  d,e 3  f 

i don't want use xmlpath or coalesce functions. in simple sql query need expected result.

since on oracle 10g version, cannot use listagg. introduced in 11g.

and please don't use wm_concat undocumented feature, , has been removed latest release. see why wm_concat not work here?

for 10g, have following string aggregation techniques:

  1. row_number() , sys_connect_by_path
  2. user-defined function stragg demonstrated tom kyte here https://asktom.oracle.com/pls/apex/f?p=100:11:0::::p11_question_id:2196162600402
  3. collect function in pl/sql

following pure sql method using row_number() , sys_connect_by_path functions available since 9i:

sql> column emp_list format a50 sql> select deptno,   2         ltrim(max(sys_connect_by_path(ename,','))   3         keep (dense_rank last order cur),',') emp_list   4    (select deptno,   5                 ename,   6                 row_number() on (partition deptno order ename) cur,   7                 row_number() on (partition deptno order ename) -1 prev   8            emp)   9  group deptno  10  connect prev = prior cur , deptno = prior deptno  11  start cur = 1;      deptno emp_list ---------- --------------------------------------------------         10 clark,king,miller         20 adams,ford,jones,scott,smith         30 allen,blake,james,martin,turner,ward  sql> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -