将多行显示为单个&单排成多排?

时间:2014-03-06 18:12:24

标签: sql oracle

需要查询才能将单行显示为多行

例如:

A,B,C,d,E,F

更改为

A

C

d

电子

˚F

查询以显示多行到单行

例如:

A

C

d

电子

˚F

更改为

A,B,C,d,E,F

2 个答案:

答案 0 :(得分:1)

SQL> with t as (
  2  select 'A,B,C,D,E,F' x from dual
  3  )
  4  select substr(x,(rownum-1)*2+1,1) from t
  5  connect by level <= regexp_count(x,',')+1
  6  /

S                                                                               
-                                                                               
A                                                                               
B                                                                               
C                                                                               
D                                                                               
E 
F     

SQL> with t as (
  2  select 'A,B,C,D,E,F' x from dual
  3  )
  4  select listagg(s,',') within group (order by s) str
  5  from (
  6  select substr(x,(rownum-1)*2+1,1) s from t
  7  connect by level <= regexp_count(x,',')+1
  8  )
  9  /

STR                                                                             
---------------
A,B,C,D,E,F    

答案 1 :(得分:0)

逗号/字符串到表:How can I select from list of values in Oracle

 select column_value from 
   table(sys.dbms_debug_vc2coll('One', 'Two', 'Three', 'Four'));

SELECT trim(regexp_substr('Err1, Err2, Err3', '[^,]+', 1, LEVEL)) str_2_tab
  FROM dual
CONNECT BY LEVEL <= regexp_count('Err1, Err2, Err3', '[^,]+')
/

表格为逗号/字符串:

 WM_CONCAT() in 10g as jle mentioned or LISTAGG() in 11g.