Post

Oracle update data by using replace

Oracle update data by using replace

I’ve used this when sensitive data accidentally ended up in a column that shouldn’t contain it — think a date in a description field that needs to be redacted. Oracle’s REPLACE function works inline in an UPDATE statement, replacing all occurrences of the target string in the column value.

Let us assume that there is a table:

1
CLIENT_COMPLAINTS

In this table there are two columns:

1
2
ID,
DESCRIPTION

By mistake someone captured client sensitive information as part of description which needs to be replaced with xxxx.

  • SQL update query to do that is:
1
2
3

UPDATE CLIENT_COMPLAINTS SET DESCRIPTION = REPLACE(DESCRIPTION, '01/2021', 'xx/xxxx') WHERE id=2154485618838;

This post is licensed under CC BY 4.0 by the author.