问题
This is my code:
DECLARE
v_grade CHAR(1) := UPPER('&grade');
appraisal VARCHAR(20);
BEGIN
appraisal := CASE v_grade
WHEN 'A' THEN 'Excellent'
WHEN 'B' THEN 'Very Good'
WHEN 'C' THEN 'Good'
WHEN 'No such grade'
END;
DBMS_OUTPUT.PUT_LINE('Grade: '||v_grade||'Appraisal '||appraisal);
END;
/
this is the full error code:
ERROR at line 10:
ORA-06550: line 10, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
* & = - + < / > at in is mod remainer not rem then
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 between || multiset member submultiset.
I'm learning PL/SQL and I was trying an example from my book but it seems I did something wrong, please don't just give the answer I want to know how you troubleshooted this and how I did make the mistake.
回答1:
Your final clause should use ELSE
instead of WHEN
:
DECLARE
v_grade CHAR(1) := 'C';
appraisal VARCHAR(20);
BEGIN
appraisal :=
CASE v_grade
WHEN 'A' THEN 'Excellent'
WHEN 'B' THEN 'Very Good'
WHEN 'C' THEN 'Good'
ELSE 'No such grade'
END;
DBMS_OUTPUT.PUT_LINE('Grade: '||v_grade||', Appraisal '||appraisal);
END;
UPDATE
Giving you advice on how to troubleshoot this isn't easy (since it's largely a matter of personal preference); things I usually try are
- narrow down the example (in your case, get rid of all additional clauses in the
CASE
) - rewrite the offending part of the query from scratch
- copy a similary query that works and change that query gradually to resemble the offending query until I encounter the error
回答2:
Rewrite code like this
DECLARE
v_grade CHAR(30) := UPPER('&grade');
appraisal VARCHAR(20);
BEGIN
appraisal := CASE v_grade
WHEN 'A' THEN 'Excellent'
WHEN 'B' THEN 'Very Good'
WHEN 'C' THEN 'Good'
ELSE 'No such grade'
END;
DBMS_OUTPUT.PUT_LINE('Grade: '||v_grade||'Appraisal '||appraisal);
END;
来源:https://stackoverflow.com/questions/36648463/pls-00103-encountered-the-symbol-end-when-expecting-etc