mysql 去掉多余的逗号,如何删除mysql查询中的空逗号

actual data (,,,demo, ,xxxx,,,yyy,,,) to be (demo,xxxx,yyy)

What I have tried:

i had triedSELECT TRIM(BOTH ',' FROM ',,,demo, ,xxxx,,,yyy,,,');

SELECT REPLACE(TRIM(TRIM(',' FROM ',,,demo, ,xxxx,,,yyy,,,')), ',,', ',');

its not removing the empty comma in between any one plz help??

解决方案Clarification required: what is this one in the query ',,,demo, ,xxxx,,,yyy,,,'

Mysql is not really meant for text manipulation

If you are using a server side language like php, you can preg_replace to remove commas in the string and send that variable to select query.

By implication (that you're using .php in your subject list) I'll presume you're generating the query.

In this case, as you add each value, if it's empty(), then insert NULL (no single quotes!) after the comma.

Alternatively, you're not generating the query directly with php, but it's being passed in to your php. In this case, you can fix all but the last comma with str_replace(',,', ',NULL,', yourString); and, since NULL's are presumbly allowed, you can the use Trim() to get rid of the last comma - or, if the last character in your string is a comma, add NULL to the end of your string.

The above is heavily dependent upon how you handle missing data: is this going to a stored procedure with default values? A table with default values? And also, how did the commas get there in the first place?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值