|
Home > Archive > Oracle certifications > April 2002 > Case
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| chukws 2002-04-12, 3:32 am |
| Hei
I want to know how to use the CASE() in PL/SQl. I am trying to programm a simple Calculator using the CASE instead of using function()
thanks | |
| stecal 2002-04-12, 5:40 pm |
| If you want to use CASE, you will need to be on Oracle9i. Otherwise, you are left with nested IF-THEN-ELSE statements (or maybe DECODE, depending on what you are trying to do). An example of using the CASE function from MetaLink is:
declare
achar char(1) := '&achar';
description varchar2(20);
begin
description :=
case achar
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('The description was ' || description);
end; | |
| pmjain 2002-04-16, 10:52 pm |
| From Oracle 8i one can also use CASE statements in SQL. Look at this example:
SELECT ename, CASE WHEN sal>1000 THEN 'Over paid' ELSE 'Under paid' END
FROM emp;
quote: Originally posted by chukws
Hei
I want to know how to use the CASE() in PL/SQl. I am trying to programm a simple Calculator using the CASE instead of using function()
thanks
| |
| stecal 2002-04-17, 10:40 am |
| Okay, which "CASE" function are you referring to? If you want a simple case for a query, the previous post will work. For PL/SQL, I'm assuming you mean CASE as in nested if-then-else statements, otherwise, you would have asked for how to use CASE in SQL, not PL/SQL. | |
| chukws 2002-04-17, 12:53 pm |
| Yes I mean "CASE" in PL/SQL. I want to programm a simple calculator. I can use simple IF-THEN-ELSE, but I understand using CASE reduces the amount of codes to write
Thanks | |
| stecal 2002-04-17, 2:38 pm |
| That's right, CASE can be used to replace nested if-then-else control structures - in Oracle9i. |
|
|
|
|