我在 MYSQL 表中有一个这样的字符串。
"Collectibles
>
Decorative Collectibles
>
Decorative Collectible Brands
>
Department 56
>
Ornaments
[ Changecategory ]"
我需要将其转换为(用逗号分隔)
Collectibles,Decorative Collectibles,Decorative Collectible Brands
,Department 56,Ornaments
我尝试用逗号替换回车符,但它不起作用。
最佳答案
试试这个。
SELECT
REPLACE(
SUBSTRING_INDEX(
'Collectibles
>
Decorative Collectibles
>
Decorative Collectible Brands
>
Department 56
>
Ornaments
[ Changecategory ]', '[', 1),
'\n >\n',',') output;
输出:
mysql> SELECT
-> REPLACE(
-> SUBSTRING_INDEX(
-> 'Collectibles
'> >
'> Decorative Collectibles
'> >
'> Decorative Collectible Brands
'> >
'> Department 56
'> >
'> Ornaments
'> [ Changecategory ]', '[', 1),
-> '\n >\n',',') output;
+--------------------------------------------------------------------------------------------------+
| output |
+--------------------------------------------------------------------------------------------------+
| Collectibles, Decorative Collectibles, Decorative Collectible Brands, Department 56, Ornaments
|
+--------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
关于mysql - 使用MYSQL删除字符串中不需要的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35882562/