Mysql generate alias column - replace non-ascii characters

Ever needed an alias column after a lot of data is inserted in table? This happened to us this week, we had to add alias column and remove non-ascii characters. This was the easy solution that we have found :).

UPDATE table_name 
    SET column_alias = REPLACE(CONVERT(column_nume USING ascii), '?', '');

Noticed then that characters like "(" or ")" were in the link. So we made another query to replace special characters in alias column.

UPDATE table_name SET column_alias = REPLACE(column_alias,")","");

Categories

Archive