--拆with tmp_table as(select'a' name1,'A,B,C,D'::varcharas t )select
name1,
regexp_split_to_table(t,',') t
from
tmp_table;--合select
name1,
string_agg(t,','orderby t) t
from(select'a' name1,'A' t
unionallselect'a' name1,'B' t
unionallselect'a' name1,'C' t
unionallselect'a' name1,'D' t
) a
groupby name1;
oracle
--拆with tmp_table as(select'a' name1
,'A,B,C,D'as t
FROM dual
)SELECT name1,regexp_substr(t,'[^,]+',1,LEVEL) t FROM tmp_table a
CONNECTBYLEVEL<= regexp_count(a.t,'\,\')+1;
--合
SELECT
name1,
listagg(t,',')WITHIN GROUP(ORDER BY t) t
FROM (
select 'a' name1,'A' t FROM dual
UNION ALL
select 'a' name1,'B' t FROM dual
UNION ALL
select 'a' name1,'C' t FROM dual
UNION ALL
SELECT 'a' name1,'D' t FROM dual
) a
GROUPBY name1;