第一张表
第二张表
最终需求
模拟创建语句:
create table a (id number,name varchar2(30),code varchar2(30));
insert into a values (1,'czb','A01,A02,A03');
select * from a;
create table b (code varchar2(30),codename varchar2(30));
insert into b values ('A01','我');
insert into b values ('A02','爱');
insert into b values ('A03','你');
select * from b;
sql语句写法:
select
id,name,code,
(select LISTAGG(codename, ', ') WITHIN GROUP (ORDER BY codename)
from b
where code in
(SELECT regexp_substr(a.code, '[^,]+', 1, LEVEL)
FROM dual
CONNECT BY LEVEL < length(a.code)))
from a;
当然不止这一种写法,也可以使用plsql的方式实现该功能。
网页标题:sql将代码替换成码表相对应的翻译
文章出自:
http://cdxtjz.cn/article/pecodo.html