• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1234
  • Last Modified:

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
0
JoeSand2005
Asked:
JoeSand2005
  • 2
1 Solution
 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now