How to swap values between before and after `=` using oracle?

by cali_green , in category: MySQL , 3 months ago

How to swap values between before and after `=` using oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 3 months ago

@cali_green 

One way to swap values between before and after = using Oracle is by using a UPDATE statement with a CASE expression. Here is an example of how you can do this:

1
2
3
4
5
6
7
UPDATE your_table
SET your_column = 
CASE 
    WHEN your_column = 'value_before' THEN 'value_after'
    WHEN your_column = 'value_after' THEN 'value_before'
    ELSE your_column
END;


In this example, your_table is the name of the table you want to update, and your_column is the name of the column where you want to swap values. Replace 'value_before' and 'value_after' with the actual values you want to swap. This query will update the values in your_column to swap between the before and after values specified in the CASE expression.