s1 := ','||'01,02,03'||','; for c in select * from B where s1 like '%,'||vertype||',%' loop s1 := replace(s1,','||c.vertype||',' , ','||c.vervalue||','); end loop; s1 := substr(s1, 2, length(s1)-2);
function f(s0 varchar2) is s1 varchar2(128); begin s1 := ','||s0||','; --',01,02,03,'; 加逗号保证分隔 for c in select * from B where s1 like '%,'||vertype||',%' loop --这么麻烦的替换是为了保证顺序,否则按照楼上的WM_CONCAT就直接出来了。 s1 := replace(s1,','||c.vertype||',' , ','||c.vervalue||','); end loop; s1 := substr(s1, 2, length(s1)-2); --去除两端逗号 return s1; end f;select vertype, f(vertype) from A;
先 len(str)-len(replace,',','') 算出一共几个逗号
然后 loop
用substr(currlen,currlen+2*i)。
s1 := ','||'01,02,03'||',';
for c in select * from B where s1 like '%,'||vertype||',%'
loop
s1 := replace(s1,','||c.vertype||',' , ','||c.vervalue||',');
end loop;
s1 := substr(s1, 2, length(s1)-2);
表A有一个字段vertype,可以为空,有值的话是以01,02(数字间以逗号分隔)形式存储。
表B有字段vertype,vervalue。对应01:手机 ,02:电脑
我希望在对A表做查询的时候,把vertype的对应的中文名称显示出来,如果vertype为空,那么也是的中文名称为空,如果有值,比如为01,02,那么需要显示为:手机,电脑。
=============================这个函数怎么写?
在线等,还望各位大神给予指点啊
s1 varchar2(128);
begin
s1 := ','||s0||','; --',01,02,03,'; 加逗号保证分隔
for c in select * from B where s1 like '%,'||vertype||',%'
loop
--这么麻烦的替换是为了保证顺序,否则按照楼上的WM_CONCAT就直接出来了。
s1 := replace(s1,','||c.vertype||',' , ','||c.vervalue||',');
end loop;
s1 := substr(s1, 2, length(s1)-2); --去除两端逗号
return s1;
end f;select vertype, f(vertype) from A;