您的位置:首页 > 数据库 > Oracle

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

2017-01-04 11:13 309 查看
经常碰到某些字段使用逗号等分隔符分割的配置,批量转换成中文说明比较麻烦。目前想到使用正则表达式匹配,总体思路如下

【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

很好,一般好,相当好
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: