Home » SQL & PL/SQL » SQL & PL/SQL » Case statement in pl/sql
Case statement in pl/sql [message #1392] Thu, 25 April 2002 10:52 Go to next message
David Jones
Messages: 4
Registered: April 2002
Junior Member
I can't seem to get a simple case statement to work in my pl/sql block, any idea's? I have tried different case statements and also get the same error. Is the case statement not valid in pl/sql? Thanks

Version Release 8.1.7.0.0

Local>DECLARE
grade CHAR(1) := 'C';
apraisal VARCHAR2(20);
BEGIN
appraisal := CASE grade
WHEN 'A' THEN 'Excellent'
WHEN 'B' THEN 'Very Good'
WHEN 'C' THEN 'Good'
WHEN 'D' THEN 'Fair'
WHEN 'F' THEN 'Poor'
ELSE 'No such grade'
END;
dbms_output.PUT_LINE (appraisal);
END;
/
CASE grade
*
ERROR at line 6:
ORA-06550: line 6, column 10:
PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
( - + mod not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string>
Re: Case statement in pl/sql [message #1395 is a reply to message #1392] Thu, 25 April 2002 12:08 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
there is a typo in ur code.
'Appraisal' and Apraisal.
SQL> ED
Wrote file afiedt.buf

1 DECLARE
2 grade CHAR(1) := 'C';
3 appraisal VARCHAR2(20);
4 BEGIN
5 appraisal := CASE grade
6 WHEN 'A' THEN 'Excellent'
7 WHEN 'B' THEN 'Very Good'
8 WHEN 'C' THEN 'Good'
9 WHEN 'D' THEN 'Fair'
10 WHEN 'F' THEN 'Poor'
11 ELSE 'No such grade'
12 END;
13 dbms_output.PUT_LINE (appraisal);
14* END;
SQL> /
Good

PL/SQL procedure successfully completed.
Previous Topic: Re: how to retrieve top 3 salaries
Next Topic: How to implement a select in an if-then statement?
Goto Forum:
  


Current Time: Sun Apr 28 07:31:46 CDT 2024