Oracle存储过程问题 “警告: 创建的过程带有编译错误。”

SFLDSIMON501055 2010-03-20 05:25:24
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;

“警告: 创建的过程带有编译错误”

好像没有错误啊?这时怎么回事啊????帮忙看一下吧
...全文
509 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SFLDSIMON501055 2010-03-21
  • 打赏
  • 举报
回复
谢谢 “ suiziguo (GuidingStar坚挺旗舰) ”!
suiziguo 2010-03-20
  • 打赏
  • 举报
回复
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;
duqiangcise 2010-03-20
  • 打赏
  • 举报
回复
你可以在执行完你的过程过通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;
47522341 2010-03-20
  • 打赏
  • 举报
回复
roll back;
-----------
rollback;

17,089

社区成员

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

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