Remove special characters from a database field

前端 未结 10 1683
梦如初夏
梦如初夏 2020-12-06 01:00

I have a database with several thousand records, and I need to strip down one of the fields to ensure that it only contains certain characters (Alphanumeric, spaces, and sin

10条回答
  •  鱼传尺愫
    2020-12-06 01:59

    There is no regular expression replacement. Use the following code to replace all special characters with '-'.

    UPDATE  SET  = REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (REPLACE (, '/', '-'), ',', '-'), '.', '-'), '<', '-'), '>', '-'), '?', '-'), ';', '-'), ':', '-'), '"', '-'), "'", '-'), '|', '-'), '\\', '-'), '=', '-'), '+', '-'), '*', '-'), '&', '-'), '^', '-'), '%', '-'), '$', '-'), '#', '-'), '@', '-'), '!', '-'), '~', '-'), '`', '-'), '', '-'), '{', '-' ), '}', '-' ), '[', '-' ), ']', '-' ), '(', '-' ), ')', '-' )
    
    
    

    Code formatted

    UPDATE
        
    SET = REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( REPLACE (, '/', '-'), ',', '-' ), '.', '-' ), '<', '-' ), '>', '-' ), '?', '-' ), ';', '-' ), ':', '-' ), '"', '-' ), "'", '-' ), '|', '-' ), '\\', '-' ), '=', '-' ), '+', '-' ), '*', '-' ), '&', '-' ), '^', '-' ), '%', '-' ), '$', '-' ), '#', '-' ), '@', '-' ), '!', '-' ), '~', '-' ), '`', '-' ), '', '-' ), '{', '-' ), '}', '-' ), '[', '-' ), ']', '-' ), '(', '-' ), ')', '-' )

    提交回复
    热议问题