Removing non-alphaNumerics in MySQL

后端 未结 5 564
既然无缘
既然无缘 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:43

    this is the solution in sql server. But the concept goes like I have created a number table and splitted the charecters and then matching those against the regular expression.

    Hope the same concept can be portrayed in mysql with a bit change and that hopefully u can do.

        declare @str varchar(50)
        set @str = '1ab3^45)(*%'
    
        declare @NumberTable table(id int)
        insert into @NumberTable(id) values(1)
        insert into @NumberTable(id) values(2)
        insert into @NumberTable(id) values(3)
        insert into @NumberTable(id) values(4)
        insert into @NumberTable(id) values(5)
        insert into @NumberTable(id) values(6)
        insert into @NumberTable(id) values(7)
        insert into @NumberTable(id) values(8)
        insert into @NumberTable(id) values(9)
        insert into @NumberTable(id) values(10)
        insert into @NumberTable(id) values(11)
        insert into @NumberTable(id) values(12)
    
        select NonAlphaChars = SUBSTRING(@str,id,1) from @NumberTable
        where SUBSTRING(@str,id,1) like '%[^a-z0-9]'
    

    NonAlphaChars

    ^
    )
    (
    *
    %
    

提交回复
热议问题