在WHERE子句中能否用数组?

bighunt 2004-06-29 04:16:02
我有一个函数如下:
return varchar2
as
type t_arr is varray(50000) of varchar2(4);
v_arr t_arr:=t_arr();
cursor t_sor is select location_id from location where llink='0';
t varchar2(4000);
i number;
num number:=1;
begin
for v_sor in t_sor loop
v_arr.extend;
v_arr(num):=v_sor.location_id;
num:=num+1;
end loop;
select count(*) into num from tool_and_status where (location_id in v_arr);
return t;
end;
在编译时提示:
行号= 15 列号= 88 错误文本= PLS-00642:local collection types not allowed in SQL statements,也就是说WHERE子句有问题,请问大家数组在这里怎样用?
...全文
175 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
atao245993 2004-06-30
  • 打赏
  • 举报
回复
select count(*) into num from tool_and_status
where (location_id in (select location_id from location where llink='0'));
为什么用数组?直接和表匹配就可以了啊?

你的函数返回t,t在你的函数中并没有实际意义
dinya2003 2004-06-30
  • 打赏
  • 举报
回复
考虑循环来实现/
Elevener 2004-06-30
  • 打赏
  • 举报
回复
这样的函数好象有点别扭,不妨退一步看看怎么分解功能去实现。
bighunt 2004-06-29
  • 打赏
  • 举报
回复
我并不是只统计记录数,而是select * from table where ...
whbxm2000 2004-06-29
  • 打赏
  • 举报
回复
你可以把数组改为,单步处理
return varchar2
as
--type t_arr is varray(50000) of varchar2(4);
--v_arr t_arr:=t_arr();
cursor t_sor is select location_id from location where llink='0';
t varchar2(4000);
cnt number:=0;
num number:=1;
begin
for v_sor in t_sor loop
select count(*) into num from tool_and_status where location_id in v_sor.location_id;

cnt:=cnt+num ;
end loop;
...
return t;
end;
bighunt 2004-06-29
  • 打赏
  • 举报
回复
就是因为字符串超出4000,我才用数组,除了把串分解以外有没有别的什么办法?
freddy2003 2004-06-29
  • 打赏
  • 举报
回复
不可以的
你可以先把数组中的数据取出组成串1,2,3,4
然后用location_id in (1,2,3,4);
Elevener 2004-06-29
  • 打赏
  • 举报
回复
直接用id串

如:where location_id in (1,2,3,4);

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧