2016-03-09 117 views
0

我在MYSQL表中有这样一个字符串。使用MYSQL删除字符串中的不需要的字符

"Collectibles 
> 
Decorative Collectibles 
> 
Decorative Collectible Brands 
> 
Department 56 
> 
Ornaments 
[ Changecategory ]" 

我需要将其转换为(即用逗号分隔)

Collectibles,Decorative Collectibles,Decorative Collectible Brands 
,Department 56,Ornaments 

我试着用替换为逗号回车,但它不工作。

回答

0

试试这个。

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) 
相关问题