自己写一个字符串分割函数
create or replace type split_tbl as table of varchar2(32767);
/
show errors;create or replace function split
(
p_list varchar2,
p_del varchar2 := ','
) return split_tbl pipelined
is
l_idx pls_integer;
l_list varchar2(32767) := p_list;
AA
l_value varchar2(32767);
begin
loop
l_idx := instr(l_list,p_del);
if l_idx > 0 then
pipe row(substr(l_list,1,l_idx-1));
l_list := substr(l_list,l_idx+length(p_del)); else
pipe row(l_list);
exit;
end if;
end loop;
return;
end split;
/
SQL> select * from table(split('one,two,three'));
one
two
three这样使用
SQL> select * from iptable
where input_ip
in (select iplist from table(split(iptable.ip_column)));
create or replace type split_tbl as table of varchar2(32767);
/
show errors;create or replace function split
(
p_list varchar2,
p_del varchar2 := ','
) return split_tbl pipelined
is
l_idx pls_integer;
l_list varchar2(32767) := p_list;
AA
l_value varchar2(32767);
begin
loop
l_idx := instr(l_list,p_del);
if l_idx > 0 then
pipe row(substr(l_list,1,l_idx-1));
l_list := substr(l_list,l_idx+length(p_del)); else
pipe row(l_list);
exit;
end if;
end loop;
return;
end split;
/
SQL> select * from table(split('one,two,three'));
one
two
three这样使用
SQL> select * from iptable
where input_ip
in (select iplist from table(split(iptable.ip_column)));
这样可以
select * from iptable where instr(iplist,'192.168.0.7')>0
数据库中IP字段存在记录192.168.0.1,192.168.0.10
192.168.0.7只要满足在那个起始IP之间就可以。