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,哪儿大侠指点下,哪儿错了,该怎么改?
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,哪儿大侠指点下,哪儿错了,该怎么改?
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;
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;
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;
-------- -------------------------------------------
5/9 PL/SQL: SQL Statement ignored
5/27 PLS-00201: 必须声明标识符 'TOTALDEPOSTIT'
5/41 PL/SQL: ORA-00904: : 标识符无效
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去掉