john
john

Reputation: 1

How do i remove string form a column in SQL?

Here is my column :

column
abc1234
abc5678
abc4567

Now I need to remove the abc only from the column. Please help me write a query.

Upvotes: 0

Views: 260

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520968

You might want to use REGEXP_REPLACE here:

UPDATE yourTable
SET col = REGEXP_REPLACE(col, '^abc', '')
WHERE col LIKE 'abc%';

If you don't care about the particular position of abc, and accept removing all occurrences of it anywhere, then we can do without regex:

UPDATE yourTable
SET col = OREPLACE(col, 'abc', '')
WHERE col LIKE 'abc%';

Upvotes: 3

Related Questions