我正在使用SQL Developer并编写此PL / SQL代码。但是当我给B选项时,我得到了错误。请帮忙。
SET SERVEROUTPUT ON
accept q_grade char prompt 'EnterGrade: '
DECLARE
v_grade CHAR(1) := UPPER(&q_grade);
v_appraisal VARCHAR(20);
BEGIN
v_appraisal := CASE v_grade WHEN v_grade = 'A' THEN 'Excellent'
WHEN v_grade = 'B' THEN 'Good'
WHEN v_grade = 'C' THEN 'FAIL'
ELSE 'NO SUCH GRADES'
END;
DBMS_OUTPUT.PUT_LINE ('Grade: ' || v_grade || ' Appraisal ' ||v_appraisal);
END;
/
错误报告:
ORA-06550: line 2, column 26: PLS-00201: identifier 'B' must be declared ORA-06550: line 2, column 9: PL/SQL: Item ignored ORA-06550: line 6, column 21: PLS-00320: the declaration of the type of this expression is incomplete or malformed ORA-06550: line 6, column 1: PL/SQL: Statement ignored ORA-06550: line 12, column 57: PLS-00320: the declaration of the type of this expression is incomplete or malformed ORA-06550: line 12, column 21: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
答案 0 :(得分:1)
您需要在v_grade
声明之后删除额外的CASE
:
BEGIN
v_appraisal := CASE WHEN v_grade = 'A' THEN 'Excellent'
/* -- here --------^ */
答案 1 :(得分:1)
变化:
v_grade CHAR(1) := UPPER('&q_grade');
和
v_appraisal := CASE WHEN v_grade = 'A' THEN 'Excellent'