17,378
社区成员
发帖
与我相关
我的任务
分享select * from A a
where exists (select sum(num) from B b where substr(a.phone_all,1,3)=b.msisdn
or substr(a.id_no,5,3)=b.msisdn
or substr(a.id_no,9,3)=b.msisdn
or substr(a.id_no,13,3)=b.msisdn
or substr(a.id_no,17,3)=b.msisdn
or substr(a.id_no,21,3)=b.msisdn having sum(num)>30);--创建类型
create or replace type type_split as table of varchar2(50);
--创建function
create or replace function split
(
p_list varchar2,
p_sep varchar2 := '|'
) return type_split pipelined
is
l_idx pls_integer;
v_list varchar2(50) := p_list;
begin
loop
l_idx := instr(v_list,p_sep);
if l_idx > 0 then
pipe row(substr(v_list,1,l_idx-1));
v_list := substr(v_list,l_idx+length(p_sep));
else
pipe row(v_list);
exit;
end if;
end loop;
return;
end split;
--测试
select * from table(split('001|009','|'));
create table A(id_no varchar(100))
insert into A select '001|002|'
union all select '001|003|005|'
union all select '003|006|009|010|'
create table B(id_no varchar(100),num int)
insert into B select '001', 10
union all select '002' , 13
union all select '003' , 17
union all select '005' , 20
select id_no from A where
exists(
select sum(num) aa from B where A.id_no like '%'+B.id_no +'%'
having sum(num)>30
)
drop table A
drop table B