Perform find replace in SQL update staement

I had an interesting problem today where I needed to update strings in a database table field based on a certain criteria.

A bad character had gotten into the URL field in the rhpRef table. The SQL updates and string that matches ‘warehouse-’ with ‘warehouse’. Ive added the where clause just to ensure only the correct rows are updated.

Here’s the code for future reference:

UPDATE rhpRef
SET    url = replace(url, 'warehouse-', 'warehouse')
WHERE  url LIKE '%warehouse-%';

Hope it might help someone else.

Advertisement

One Response to “Perform find replace in SQL update staement”

  1. site yonetimi Says:

    thanks for shared

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.