Reputation: 16033
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 |
Upvotes: -1
Views: 379
Reputation: 12998
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
Upvotes: 2
Reputation: 3475
If you are using MySQL 8.0, you could try REGEXP_REPLACE function.
SELECT REGEXP_REPLACE(name, "(.)(?!$)", "$1,")
FROM my_table
See demo here
Upvotes: 1