Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to separate comma separated values in oracle 11G

I need to separate the value of a column by commas.

Example: BCDEY; I need to convert to a B, C, D, E, Y. Follows the "select":

SELECT CDGRUPOCONDICAO FROM TBINTCLIENTE;
like image 668
Edinei Raduvanski Avatar asked Dec 29 '25 10:12

Edinei Raduvanski


2 Answers

You can try also this:

with cad as  
(select 'BCDEY' cad from dual)
select regexp_replace (regexp_replace(cad,'(.)','\1, '),', $','') cad_comma from cad;
like image 167
Aramillo Avatar answered Jan 01 '26 07:01

Aramillo


Something like that maybe?

with testdata as (select 'BCDEY' str from dual)

select listagg(c, ', ') within group(order by lvl)
from (
  select substr(str, level, 1) c,
         level lvl
  from testdata
  connect by level <= length(str)
  )

Producing:

B, C, D, E, Y

Here, the subquery split the string character by character. Then the outer listagg re-assemble the items by joining them with ', '.

like image 44
Sylvain Leroux Avatar answered Jan 01 '26 07:01

Sylvain Leroux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!