您的位置:首页 > 数据库 > Oracle

oracle 存储过程中,解决变量使用 in条件时,查询无效问题

2020-07-12 17:42 344 查看

oracle 存储过程中,定义变量之后,使用变量进行 in 条件查询时,会出现查询条件无效的问题

  • 表结构
  • 表数据
  • 解决方法
create or replace type strsplit_type is table of varchar2(30000);
create or replace function strsplit(para_str varchar2, para_split varchar2 := ',')

return strsplit_type

pipelined is

do_idx integer;
do_str varchar2(500);
do_last varchar2(4000) := para_str;

begin

if substr(para_str, length(para_str)) = '|' then

do_last := substr(para_str, 1, length(para_str) - 1);

end if;

loop

do_idx := instr(do_last, para_split);
exit when do_idx = 0;
do_str := substr(do_last, 1, do_idx - 1);
do_last := substr(do_last, do_idx + 1);
pipe row(do_str);
end loop;

pipe row(do_last);

return;

end strsplit;
  • 传参方式
select * from table(strsplit('n1|n2|n3|n4', '|'));

  • 调用
select * from DEPT t where t.dname in (select * from table(strsplit('n1|n2|n3|n4', '|')));

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: