在MYSQL中用单引号将每个项目的字符串拆分

2vuwiymt  于 2023-02-15  发布在  Mysql
关注(0)|答案(1)|浏览(138)

我有个简单的问题...

Set @SQl1 = '415,417,418,419,420,416';
Set @SQl2 = REPLACE(@SQl1,","," ',' ");
Select @SQl1, @SQl2;

结果是-

@SQl1 = '415,417,418,419,420,416'
@SQl2 = '415 '','' 417 '','' 418 '','' 419 '','' 420 '','' 416'

但我想要这样的结果

@SQL2 = '415','417','418','419','420','416'

尝试了许多函数,如replace、Substring、json_unquote、quote ......但没有成功......
有人能帮忙吗?

hc2pp10m

hc2pp10m1#

Set @SQL1 = '415,417,418,419,420,416';
Set @SQL2 = CONCAT('''', REPLACE(@SQL1,',', ''','''), '''');
Select @SQL1, @SQL2;

产出
| @SQL1|@SQL2|
| - ------|- ------|
| 415,417,418,419,420,416美元|“四一五”、“四一七”、“四一八”、“四一九”、“四二零”、“四一六”|
不要用双引号字符"引用字符串--它们会被用于JSON路径/值。

相关问题