oracle 根据逗号拆分字段内容转成多行

  先虚拟一张表

	select '华为,小米,苹果,vivo,oppo,' brand,'手机' name  from dual 
  	union all
  	select '华为,小米,苹果' brand, '电脑' name from dual

                  在这里插入图片描述

select distinct * from (
select regexp_substr(a.brand, '[^,]+', 1, Level,'i') brand,name
  from (
  	select '华为,小米,苹果,vivo,oppo,' brand,'手机' name  from dual 
  	union all
  	select '华为,小米,苹果' brand, '电脑' name from dual
  ) a
connect by Level <= LENGTH(a.brand) - LENGTH(REGEXP_REPLACE(a.brand, ',', '')) + 1) 
where brand is not null  order by name;

拆分后
                  oracle 根据逗号拆分字段内容转成多行_第1张图片

你可能感兴趣的:(oracle)