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,哪儿大侠指点下,哪儿错了,该怎么改?

解决方案 »

  1.   

    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; 
      

  2.   

    试试
    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; 
      

  3.   

    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; 
      

  4.   

    oracle语法就是如此,不用declare
      

  5.   

    如果去掉declare,错误如下PROCEDURE TRANSFER 出现错误:LINE/COL ERROR
    -------- -------------------------------------------
    5/9      PL/SQL: SQL Statement ignored
    5/27     PLS-00201: 必须声明标识符 'TOTALDEPOSTIT'
    5/41     PL/SQL: ORA-00904: : 标识符无效
      

  6.   

    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去掉