Oracle SQL批量收集和计数

Oracle SQL批量收集和计数,oracle,plsql,Oracle,Plsql,我有一个数据库,里面有人的身份证和他们所欠的钱。。 在de数据库中,可以在不同的行上多次找到一个人 我需要收集所有打开的金额高于140的人,并在表中获取他们的所有信息(表名为money) 我尝试使用select语句,使count(Cashdue)>140,但他不允许批量收款 你知道我如何在大量收集信息的同时只统计总金额超过140美元的人吗 提前谢谢 DECLARE Type type_coll_number is table of money.userid%type; t_mone

我有一个数据库,里面有人的身份证和他们所欠的钱。。 在de数据库中,可以在不同的行上多次找到一个人

我需要收集所有打开的金额高于140的人,并在表中获取他们的所有信息(表名为money)

我尝试使用select语句,使count(Cashdue)>140,但他不允许批量收款

你知道我如何在大量收集信息的同时只统计总金额超过140美元的人吗

提前谢谢

DECLARE
  Type type_coll_number
  is table of money.userid%type;

  t_moneydue type_coll_number;
BEGIN
  select money.userid
  bulk collect into t_moneydue
  from money
  group by userid
  having count(Cashdue) > 140;

  for i in 1 .. t_moneydue.count
  loop
    dbms_output.put_line(t_moneydue(i));
  end loop;
END;

将我的评论变成回答:-)


您可能希望sum(cashdue)>140而不是count

只需将其放在另一个查询中:

select userid
bulk collect into t_moneydue
from (
  select money.userid 
  from money
  group by userid
  having sum(Cashdue) > 140
);

你可能想让sum(cashdue)>140而不是countOmg,我不敢相信我没有弄明白-是的,我也明白了。你盯着一个问题看得太久了,你看不到显而易见的闪光:)