ORA-06550:第9行,第17栏:PLS-00201:

时间:2014-08-08 05:39:09

标签: oracle

DECLARE 
    acct_balance NUMBER(11, 2); 
    acct_num     VARCHAR2(10); 
    trans_amt    NUMBER(11, 2); 
    oper         CHAR(1); 
    more_than_balance EXCEPTION; 
    PRAGMA EXCEPTION_INIT (more_than_balance, -00054); 
BEGIN 
    acct_num := &acct_num; 

    trans_amt := &trans_amt; 

    oper := &oper; 

    SELECT curbal 
    INTO   acct_balance 
    FROM   acct_mstr 
    WHERE  acct_no = acct_num; 

    IF oper = 'D' THEN 
      IF trans_amt < acct_balance THEN 
        UPDATE acct_mstr 
        SET    curbal = curbal - trans_amt 
        WHERE  acct_no = acct_num; 
      ELSE 
        RAISE more_than_balance; 
      END IF; 
    ELSIF oper = 'C' THEN 
      UPDATE acct_mstr 
      SET    curbal = curbal + trans_amt 
      WHERE  acct_no = acct_num; 
    END IF; 
EXCEPTION 
    WHEN more_than_balance THEN 
dbms_output.Put_line('attempted to withdraw more than the current balance ' || acct_balance ||'from the account numebr' ||acct_num); 
END; 

获取

ORA-06550: line 9, column 17:
PLS-00201: identifier 'D' must be declared
ORA-06550: line 9, column 5:
PL/SQL: Statement ignored
ORA-06550: line 10, column 18:
PLS-00201: identifier 'C' must be declared

2 个答案:

答案 0 :(得分:1)

acct_num和oper是varchar / char字段,它应该是单引号...如下所示

    acct_num := '&acct_num'; 
    oper := '&oper';

答案 1 :(得分:0)

删除oper := &oper;

并在你的if条件下试试这个:

IF &oper := 'D' THEN 

同样

ELSIF &oper := 'C' THEN

所以你的查询就像:

DECLARE 
    acct_balance NUMBER(11, 2); 
    acct_num     VARCHAR2(10); 
    trans_amt    NUMBER(11, 2); 
    oper         CHAR(1); 
    more_than_balance EXCEPTION; 
    PRAGMA EXCEPTION_INIT (more_than_balance, -00054); 
BEGIN 
    acct_num := &acct_num; 

    trans_amt := &trans_amt; 

    SELECT curbal 
    INTO   acct_balance 
    FROM   acct_mstr 
    WHERE  acct_no = acct_num; 

    IF &oper := 'D' THEN 
      IF trans_amt < acct_balance THEN 
        UPDATE acct_mstr 
        SET    curbal = curbal - trans_amt 
        WHERE  acct_no = acct_num; 
      ELSE 
        RAISE more_than_balance; 
      END IF; 
    ELSIF &oper := 'C' THEN 
      UPDATE acct_mstr 
      SET    curbal = curbal + trans_amt 
      WHERE  acct_no = acct_num; 
    END IF; 
EXCEPTION 
    WHEN more_than_balance THEN 
dbms_output.Put_line('attempted to withdraw more than the current balance ' || acct_balance ||'from the account numebr' ||acct_num); 
END; 
相关问题