要求:每个产品信息表中的库存量=该产品进货的总量-该产品出货的总量,设计一个程序实现输入一产品编号,更新该产品的库存量
declare
v_pid tab_ingoods.pid%type;
V_innum  tab_ingoods.innum%type;
V_outnum  tab_outgoods.outnum%type;
v_stocks number(12,2);
begin
v_pid:=&pid;
select innum,outnum 
into V_innum,V_outnum
from tab_ingoods a,tab_outgoods b
where a.pid=b.pid and a.pid=V_pid;
v_stocks:=V_innum-V_outnum;
update tab_product set stocks=v_stocks where pid=V_pid;
exception
when others then
DBMS_output.put_line(SQLERRM);
end;
但是 当执行后会出现"实际返回的行数超出请求行数"
/
请问怎么样处理?

解决方案 »

  1.   

    最有可能出现问题的是:
    select   innum,outnum   
    into   V_innum,V_outnum 
    from   tab_ingoods   a,tab_outgoods   b 
    where   a.pid=b.pid   and   a.pid=V_pid; 
    可能这语句不返回唯一结果,但是这个可以看出可能数据库里面的数据有点错误哦,修改如下看看:
    select   innum,outnum   
    into   V_innum,V_outnum 
    from   tab_ingoods   a,tab_outgoods   b 
    where   a.pid=b.pid   and   a.pid=V_pid and rownum<2; 
      

  2.   

    必须控制
    select   innum,outnum   
    from   tab_ingoods   a,tab_outgoods   b 
    where   a.pid=b.pid   and   a.pid=V_pid;
    返回单行。否则,必须使用 cursor... fetch的方式处理。