Perform regex (replace) in an SQL query

后端 未结 6 1543
闹比i
闹比i 2020-12-01 11:08

What is the best way to replace all \'<\' with < in a given database column? Basically perform s/<[^;]/</gi

Notes

6条回答
  •  Happy的楠姐
    2020-12-01 11:34

    How about:

        UPDATE tableName
        SET columName = REPLACE(columName , '<', '<')
        WHERE columnName LIKE '%lt%'
        AND columnName NOT LIKE '%lt;%'
    

    Edit:

    I just realized this will ignore columns with partially correct < strings.

    In that case you can ignore the second part of the where clause and call this afterward:

        UPDATE tableName
        SET columName = REPLACE(columName , '<;', '<')
    

提交回复
热议问题