第一張表
第二張表
最終需求
模擬創(chuàng)建語句:
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;
當(dāng)然不止這一種寫法,也可以使用plsql的方式實(shí)現(xiàn)該功能。
當(dāng)前題目:sql將代碼替換成碼表相對(duì)應(yīng)的翻譯
網(wǎng)站鏈接:
http://weahome.cn/article/pecodo.html