skip to Main Content

Is it possible to add a comma between each character of a string on mysql.

From my_table

id name
1 hello

To :

id name
1 h,e,l,l,o

2

Answers


  1. If you are using MySQL 8.0, you could try REGEXP_REPLACE function.

    SELECT REGEXP_REPLACE(name, "(.)(?!$)", "$1,")
    FROM my_table
    

    See demo here

    Login or Signup to reply.
  2. Another MySQL8 REGEXP_REPLACE –

    SELECT id, REGEXP_REPLACE(name, '(?=.)(?<=.)', ',')
    FROM my_table;
    

    db<>fiddle and regular expressions 101

    Since MySQL 8.0.4 the regex implementation has been using International Components for Unicode (ICU)patterns and behavior are based on Perl’s regular expressions

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search