create or replace procedure SaleOut(goodNo VARCHAR2, outAmount NUMBER)
As declare
amount number;
Begin
select Gamount into amount from Goods where Gno=goodNo;
if amount=0 then
roll back;
return;
end if;
if amount < outAmount then
roll back;
return;
end if;
Update Goods Set Gamount=Gamount-outAmount where Gno=goodNo;
commit;
end;“警告: 创建的过程带有编译错误”好像没有错误啊?这时怎么回事啊????帮忙看一下吧

解决方案 »

  1.   

    roll back;
    -----------
    rollback;
      

  2.   

    你可以在执行完你的过程过通show errors;命令在sqlplus中查看异常信息。
    另外你上面创建的是一个过程不是函数,不能够使用return语句。还有As declare
    的地方,在过程中只能够使用as或is,不能够使用declare.
    对你的过程修改如下:
    create or replace procedure SaleOut(goodNo VARCHAR2, outAmount NUMBER)
    As 
    amount number;
    Begin
    select Gamount into amount from Goods where Gno=goodNo;if (amount=0 or amount < outAmount)then
    roll back;
    end if;Update Goods Set Gamount=Gamount-outAmount where Gno=goodNo;
    commit;
    exception 
    when others then
    --此处应捕获一下异常,因为如果select Gamount into amount from Goods where Gno=goodNo语句没有查询出
    --满足条件的记录时,会抛出异常
    null;end;
      

  3.   

    create or replace procedure SaleOut(goodNo VARCHAR2, outAmount NUMBER)
    AS
    amount number;
    Begin
    select Gamount into amount from Goods where Gno=goodNo;
    if amount=0 then
    ROLLBACK;
    return;
    end if;
    if amount < outAmount then
    ROLLBACK;
    return;
    end if;
    Update Goods Set Gamount=Gamount-outAmount where Gno=goodNo;
    commit;
    end;
      

  4.   

    谢谢 “ suiziguo (GuidingStar坚挺旗舰) ”!