问题
I have the following string: "a,b,c,d"
and I want to convert it into a json array, something like this ["a","b","c","d"]
is there any MySQL 8 function that can achieve this?
回答1:
Try:
SELECT
CAST(
CONCAT('["', REPLACE('a,b,c,d', ',', '","'), '"]')
AS JSON
);
See dbfiddle.
回答2:
select json_array("a,b,c,d");
+-----------------------+
| json_array("a,b,c,d") |
+-----------------------+
| ["a,b,c,d"] |
+-----------------------+
来源:https://stackoverflow.com/questions/56958056/mysql-8-split-string-by-comma-and-convert-it-into-json-array