How to replace all values of a given table in MYSQL at once?

0

I have a table ( produtos ) that has column product_params

Several products have the value of this table with max_order_level="" and I want to replace all of them with max_order_level="1" , that is, change the empty value of max_order_level to 1.

Is there a way I can do this all at once?

    
asked by anonymous 22.05.2018 / 20:06

1 answer

1

Yes. There must be several, here's one of them:

You can use the function REPLACE (not to be confused with the command REPLACE ) in the update. It will return you to the original full string, with only the requested part replaced.

So:

UPDATE produtos
    SET product_params = REPLACE(product_params, 'max_order_level=""', 'max_order_level="1"')  
WHERE product_params LIKE '%max_order_level=""%'

The only restriction would be for the product to have this parameter set as you expect ( max_order_level="" ), only to reduce the amount of affected records to those that will actually be.

See this example working in sql fiddle.

    
22.05.2018 / 21:06