PL/SQL Case Statement

Hi Guys,

I need to update a column base on values from another column. Lets say I have a table Cust with fields
Sales and Bracket. Sales has the actual values and Bracket is null. I'd like to create a Case statement to the following break down

IF Sales >= 0 and Sales < 150 Then
       Bracket = 1
Else IF Sales >= 150 and Sales < 300 Then
       Bracket  = 2
Else IF Sales >= 300 and Sales < 600 Then
       Bracket = 3
Else IF Sales >= 600 and Sales < 900 Then
       Bracket = 4
Else IF Sales >= 900 Then
       Bracket = 5
End IF;

Thanks so very much for your help!

Joe
JoeSand2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pennnnCommented:
UPDATE cust
      SET bracket = CASE
                              WHEN sales BETWEEN 0    AND 149 THEN 1
                              WHEN sales BETWEEN 150 AND 299 THEN 2
                              WHEN sales BETWEEN 300 AND 599 THEN 3
                              WHEN sales BETWEEN 600 AND 899 THEN 4
                              WHEN sales >= 900 THEN 5
                            ELSE null -- or whatever default value you choose
                            END;

Hope that helps!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JoeSand2005Author Commented:
Hi Pennnn,

I tried your code and I got this error message
ERROR at line 2:
ORA-00600: internal error code, arguments: [kkmgpvc2], [], [], [], [], [], [],
[]
Do you have any idea why?

Thanks!
Joe
0
JoeSand2005Author Commented:
Hey Pennnn,

I got it, problem solve, your code works pretty good. I really appreciate your help
Thanks!

Joe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.