oracle用逗号分隔符分割的字段,转换中文说明

来源:互联网 发布:数据库关联查询sql语句 编辑:程序博客网 时间:2024/05/28 06:06

经常碰到某些字段使用逗号等分隔符分割的配置,批量转换成中文说明比较麻烦。目前想到使用正则表达式匹配,总体思路如下
【1】 先由一行用正则表达式提取分割成多行。
【2】 再用参数表查询中文名
【3】 再合成一行
—参数中文说明表
select id,name from tab_mb
id name
501 很好
502 一般好
503 相当好

—测试数据
select ‘501,502,503’ as source_string from dual

with t1 as
(select ‘501,502,503’ as source_string from dual),
t2 as
(select regexp_substr(source_string, ‘[^,]+’, 1, rownum) need_string
from t1
connect by rownum <=
length(source_string) - length(replace(source_string, ‘,’, ”)) + 1),
t3 as
(select need_string,
(select name from tab_mb h where a.need_string = h.id) need_string_name
from t2 a)
select to_char(wmsys.wm_concat(need_string_name)) as source_2_need from t3

结果输出
source_2_need
很好,一般好,相当好

1 0