create or replace function dic_conver(dic_code in varchar2,
dic_type in varchar2,
str_type in varchar2)
/*
dic_code:要转换的字符串,例:02,03,04
dic_type:字典类型,注意:传入的字符串一定要和函数里定义的一致,包括大小写
如果还有,可以自己增加
另外,如果字典值比较多,可以再增加一个table字典,关联表查询
str_type:分隔符类型,注意:除特殊字符外,比如‘,||等
*/
return varchar2 is
dic_name varchar2(500);
begin
with temp as
(SELECT TRIM(substr(txt,
instr(txt, str_type, 1, LEVEL) + 1,
instr(txt, str_type, 1, LEVEL + 1) -
instr(txt, str_type, 1, LEVEL) - 1)) AS txt_code
FROM (SELECT str_type || dic_code || str_type txt FROM dual)
CONNECT BY LEVEL <=
length(dic_code) - length(REPLACE(dic_code, str_type, '')) + 1)
select listagg(case
when dic_type = 'DISABLE_TYPE' then --字典类型是残疾类别
decode(a.txt_code, 'aa', '啊啊', 'bb', '报表', 'cc', '存储')
when dic_type = 'DISABLE_GRADE' then --字典类型是残疾等级
decode(a.txt_code, 'nn', '那你')
end,
str_type) within GROUP(ORDER BY a.txt_code)
into dic_name
from temp a;
return dic_name;
end;
调用示例