oracle 一个存储过程的问题,在线等

csuxp2008 2009-04-21 03:57:49
create procedure transfer(in_account int,out_account int,amount float)
as declare
totalDeposit float;
begin
select total into totalDepostit from account where accountnum = out_account;
if totalDeposit is null then
rollback;
return;
end if;
if totalDeposit < amount then
rollback;
return;
end if;
update account set total = total - amount where accountnum = out_account;
update account set total = total + amount where accountnum = in_account;
commit;
end;

下面是show error:
PROCEDURE TRANSFER 出现错误:

LINE/COL ERROR
-------- -----------------------------------------------------------
2/8 PLS-00103: 出现符号 "DECLARE"在需要下列之一时:
begin function package
pragma procedure subtype type use <an identifier>
<a double-quoted delimited-identifier> form current cursor
external language

这是一个银行帐户转帐的procedure,哪儿大侠指点下,哪儿错了,该怎么改?
...全文
105 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
semifish 2009-04-21
  • 打赏
  • 举报
回复
哈哈,多了一个t
csuxp2008 2009-04-21
  • 打赏
  • 举报
回复
确实,还是楼上的细心,真没发现
superhsj 2009-04-21
  • 打赏
  • 举报
回复
晕啊,你声明的和用的写的不一样,差个t,改过来就可以了
[Quote=引用 6 楼 csuxp2008 的回复:]
如果去掉declare,错误如下

PROCEDURE TRANSFER 出现错误:

LINE/COL ERROR
-------- -------------------------------------------
5/9 PL/SQL: SQL Statement ignored
5/27 PLS-00201: 必须声明标识符 'TOTALDEPOSTIT'
5/41 PL/SQL: ORA-00904: : 标识符无效
[/Quote]
mrdavidtian 2009-04-21
  • 打赏
  • 举报
回复
create procedure transfer(in_account int,out_account int,amount float)
as declare
totalDeposit float;
begin
select total into totalDepostit from account where accountnum = out_account;
if totalDeposit is null then
rollback;
return;
end if;
if totalDeposit < amount then
rollback;
return;
end if;
update account set total = total - amount where accountnum = out_account;
update account set total = total + amount where accountnum = in_account;
commit;
end;
把第二行的DECLARE去掉
csuxp2008 2009-04-21
  • 打赏
  • 举报
回复
哪位大虾知道原因,如何解决?
csuxp2008 2009-04-21
  • 打赏
  • 举报
回复
如果去掉declare,错误如下

PROCEDURE TRANSFER 出现错误:

LINE/COL ERROR
-------- -------------------------------------------
5/9 PL/SQL: SQL Statement ignored
5/27 PLS-00201: 必须声明标识符 'TOTALDEPOSTIT'
5/41 PL/SQL: ORA-00904: : 标识符无效
superhsj 2009-04-21
  • 打赏
  • 举报
回复
oracle语法就是如此,不用declare
csuxp2008 2009-04-21
  • 打赏
  • 举报
回复
totalDeposit 需要声明
阿三 2009-04-21
  • 打赏
  • 举报
回复
create or replace procedure transfer(in_account int,out_account int,amount float)
as
totalDepostit float;
begin
select total into totalDepostit from account where accountnum = out_account;
if totalDepostit is null then
--rollback; 这里不用回滚
return;
end if;
if totalDepostit < amount then
--rollback;
return;
end if;
update account set total = total - amount where accountnum = out_account;
update account set total = total + amount where accountnum = in_account;
commit;
  exception
when others then rollback; --出错回滚
end;
superhsj 2009-04-21
  • 打赏
  • 举报
回复
试试
create procedure transfer(in_account in number,out_account in number,amount in number) 
as
totalDeposit number;
begin
select total into totalDepostit from account where accountnum = out_account;
if totalDeposit >= amount then
update account set total = total - amount where accountnum = out_account;
update account set total = total + amount where accountnum = in_account;
commit;
else
rollback;
end if;
end;
kk19840210 2009-04-21
  • 打赏
  • 举报
回复
create procedure transfer(in_account int,out_account int,amount float)
as

totalDeposit float;
begin
select total into totalDepostit from account where accountnum = out_account;
if totalDeposit is null then
rollback;
return;
end if;
if totalDeposit < amount then
rollback;
return;
end if;
update account set total = total - amount where accountnum = out_account;
update account set total = total + amount where accountnum = in_account;
commit;
end;

17,082

社区成员

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

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