【发布时间】: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