在sql中把字符串"1,2,3,4,5,6"切割之后放到一个数组里的的方法,写一个案例
时间: 2023-03-16 12:44:12 浏览: 69
答:一个示例案例如下:
SET @numbers = '1,2,3,4,5,6';
SELECT
CAST(SUBSTRING_INDEX(@numbers, ',', 1) AS UNSIGNED) AS number1,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@numbers, ',', 2), ',', -1) AS UNSIGNED) AS number2,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@numbers, ',', 3), ',', -1) AS UNSIGNED) AS number3,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@numbers, ',', 4), ',', -1) AS UNSIGNED) AS number4,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@numbers, ',', 5), ',', -1) AS UNSIGNED) AS number5,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@numbers, ',', 6), ',', -1) AS UNSIGNED) AS number6;
阅读全文