Search code examples
mysqlconcatenationgenerated

mysql Create a Generated Column and Remove Specific Characters


I am creating a generated column using "concat", but i also need to have an "*" and "-" removed. Can you do multiple functions when creating a generated column?


Solution

  • You need to nest the functions. Use the result of one function as parameter for the next one:

    create table test (
      col1 varchar(50),
      col2 varchar(50),
      col3 varchar(100) as (replace(replace(concat(col1, col2), '*', ''), '-', ''))
    );
    

    Demo: http://rextester.com/KFAAO96832