I use the tip given by @user6026, but I had problem with the slowness, it seems that the function is a little slow in execution, even with only due fields treated, I did several tests.
As the idea is to treat only CPF and CNPJ, I ended up doing another function to treat only these cases, see below:
CREATE DEFINER=`root`@`localhost` FUNCTION `fLimpaCPFCNPJ`(`str` VARCHAR(20))
RETURNS varchar(20) CHARSET latin1
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
return replace(replace(replace(str, '/', ''), '-', ''), '.', '');
END
It is worth remembering that I am not DBA and I wish that those who have more experience could make the appropriate corrections.
The tests were much faster
I’ve seen an answer to that here but I can’t find it.
– Jorge B.
@bfavaretto the HTML was just to format the content!
– Vitor Molina
OK Vitor. I edited to clean your formatting marks, see how you can get the same visual result without any HTML.
– bfavaretto
Do you really need this procedure to run in the database? Why doesn’t it replace in the programming? In addition to being easier, you’ll get more performance...
– rizidoro
@rizidoro am making the conversion from one database to another using the query Insert into(values,...) Select values ... and would like to remove the letters and special characters in the select itself! but if I don’t get a solution I’ll have to accomplish in programming.
– Vitor Molina
In my view, the best way would be to actually treat this data in a high-level language.
– Jorge B.