Remove ALL or particular Non printable character from column in mysql

谁都会走 提交于 2019-12-06 05:33:47
Ronak Shah
DROP function IF EXISTS mysql_replaceallnonprintablecharacters; 

CREATE function mysql_replaceallnonprintablecharacters (data VARCHAR(1024)) 
returns VARCHAR(1024) 
begin 
  DECLARE i INT DEFAULT 0; 

  DECLARE finaldata VARCHAR(1024) DEFAULT ''; 

  SET FINALDATA:=data; 

  WHILE i < 31 do 
    SET FINALDATA:=REPLACE(finaldata, CHAR(i), ''); 
    SET i := i+1; 
  end WHILE; 

  RETURN finaldata; 
end 

MySQL doesn't support regex replace operations natively, only searches.

That said, there are packages that do provide some functionality like Oracle's REGEXP_REPLACE() as User defined functions.

The regular expression [[:cntrl:]]+ matches one or more non-printable characters (ASCII 0-31 and ASCII 127).

So, using the abovementioned package, REGEXP_REPLACE?(text, "[[:cntrl:]]+", "") will modify text by stripping it of all non-printable characters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!