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?