【问题标题】:ORA-06550: line 9, column 17: PLS-00201:ORA-06550:第 9 行,第 17 列:PLS-00201:
【发布时间】:2014-08-08 17:08:10
【问题描述】:
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

【问题讨论】:

  • Thomas Kyte 希望我们使用 VARCHAR2 类型,CHAR 类型与 VARCHAR2 相比没有优势。所以不要使用CHAR 类型。

标签: oracle


【解决方案1】:

acct_num 和 oper 是 varchar/char 字段,应该用单引号括起来...如下

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

【讨论】:

    【解决方案2】:

    删除oper := &amp;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; 
    

    【讨论】:

    • @Rajesh123:- 不客气。如果对您有帮助,请接受此作为答案!
    猜你喜欢
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 2015-02-06
    相关资源
    最近更新 更多