Removing non-alphaNumerics in MySQL

后端 未结 5 518
既然无缘
既然无缘 2021-01-14 07:27

Do you know any easy way to remove (or replace) all non alphanumeric characters from varchar variable in Mysql?

something like String\'s replaceAll(\"[^a-zA-Z0-9]\",

5条回答
  •  被撕碎了的回忆
    2021-01-14 07:40

    Since MySQL 8.0 you can use regular expression to remove non alphanumeric characters from a variable. There is method REGEXP_REPLACE

    SELECT REGEXP_REPLACE(@variable, '[^0-9a-zA-Z ]', '')
    

    or

    SET @variable = REGEXP_REPLACE(@variable, '[^0-9a-zA-Z ]', '')
    

提交回复
热议问题