We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

PL/SQL Case Statement

JoeSand2005
JoeSand2005 asked
on
Medium Priority
1,246 Views
Last Modified: 2008-01-09
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
Comment
Watch Question

Commented:
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!

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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

Author

Commented:
Hey Pennnn,

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

Joe
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.