Thursday 21 January 2010

Search and replace in SQL

Have a situation where had to change a bunch of values on a one-off in a db. Could have written a script to do it, but found this really useful tip

UPDATE table_name SET field_name = REPLACE(field_name, 'old_string','new_string')

works to change:
/OLD/PATH/TO/SOMEDATA/A_FILES

to:
/NEW/PATH/TO/A_LOT/MORE/NEW_DATA/A_FILES

No comments:

Post a Comment