表 A
编码 名称
01 a
02 b
03 c
给定一组含有重复编码的字符串:
'01,01,02'
怎么用SQL语句按字符串中的编码顺序返回如下结果:
01 a
01 a
02 b我试过这个语句
select 编码 from A instr('01,01,02',编码)>0
但只能返回两条记录
请教一下还有没有别的语句?
编码 名称
01 a
02 b
03 c
给定一组含有重复编码的字符串:
'01,01,02'
怎么用SQL语句按字符串中的编码顺序返回如下结果:
01 a
01 a
02 b我试过这个语句
select 编码 from A instr('01,01,02',编码)>0
但只能返回两条记录
请教一下还有没有别的语句?
select 编码,名称 from A where instr('01,01,02',编码)>0
select 编码,名称 from A where 编码 =substr('01,01,02',1,2)
union all
select 编码,名称 from A where 编码 =substr('01,01,02',4,2)
union all
select 编码,名称 from A where 编码 =substr('01,01,02',7,2)
数据量大用存储过程
CREATE OR REPLACE TYPE "TBL_STR" as table of varchar2(4000);Select B.编码,A.名称 From (Select Column_Value As 编码 From Table(Cast(To_Table('01,01,02', ',') As Tbl_Str))) B,A Where B.编码=A.编码
as
ltab tbl_str := tbl_str();
pos integer := 0;
ls varchar2(4000) := pv_str;
begin
pos := instr(ls,pv_split);
while pos > 0 loop
ltab.extend;
ltab(ltab.count) := substr(ls,1,pos - 1);
ls := substr(ls,pos + length(pv_split));
pos := instr(ls,pv_split);
end loop;
ltab.extend;
ltab(ltab.count) := ls;
return ltab;
end;
自己尝试写吧。我最早写的第一个存储过程就是写类似的,自己写印象深刻