Home » SQL & PL/SQL » SQL & PL/SQL » How to use the CASE STATEMENT in PL/SQL
How to use the CASE STATEMENT in PL/SQL [message #121895] Wed, 01 June 2005 11:47 Go to next message
hqluu18
Messages: 2
Registered: June 2005
Junior Member
Case statement doesn't seem to work in a PL/SQL block.
Please dummy example below:

procedure test is
x number :=1;
y number;
begin
case x
when 1 then y:= 1
when 2 then y:= 2
else y := 0
end
ORA-06550: line 2, column 4:
PLS-00103: Encountered the symbol "CASE" when expecting one of the following:

begin declare exit for goto if loop mod null pragma raise
return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall
<a single-quoted SQL string>


end
end
ORA-00900: invalid SQL statement

Re: How to use the CASE STATEMENT in PL/SQL [message #121897 is a reply to message #121895] Wed, 01 June 2005 11:51 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
If you are using 8i, I don't think CASE was supported yet in PL/SQL.

You are also missing semicolons on almost every line in your code.
Re: How to use the CASE STATEMENT in PL/SQL [message #121915 is a reply to message #121897] Wed, 01 June 2005 14:22 Go to previous messageGo to next message
hqluu18
Messages: 2
Registered: June 2005
Junior Member
Thank you.
Re: How to use the CASE STATEMENT in PL/SQL [message #361937 is a reply to message #121895] Fri, 28 November 2008 11:22 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member


Quote:
procedure test is
x number :=1;
y number;
begin
case x
when 1 then y:= 1
when 2 then y:= 2
else y := 0
end


And rather it should be ,

y:=
case x
   when 1 then  1
   when 2 then  2
   else 0
end; 


Smile
Rajuvan.
Re: How to use the CASE STATEMENT in PL/SQL [message #361942 is a reply to message #361937] Fri, 28 November 2008 11:34 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Wow! dig up a three and half years old post for this? How deep will you dig in the forum?

Regards
Michel
Re: How to use the CASE STATEMENT in PL/SQL [message #361946 is a reply to message #121895] Fri, 28 November 2008 11:43 Go to previous message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member

Ooops . .

I don't know ,how and why I posted answer for 3.5 year old post.

I think its time definitely to go to bed.

Bye

Smile
Rajuvan.

[Updated on: Fri, 28 November 2008 11:44]

Report message to a moderator

Previous Topic: Time is not saved with date.
Next Topic: trigger problem
Goto Forum:
  


Current Time: Sat Dec 03 15:56:33 CST 2016

Total time taken to generate the page: 0.08062 seconds