解决您的问题需要使用numbers
表格:整数表格,1,2,3,.... 直到某个合理的值,例如 1024。
然后,您将使用字符串遍历来解决问题。
这是表的 CREATE TABLE 语句numbers
:
CREATE TABLE numbers (
`n` smallint unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`n`)
)
;
INSERT INTO numbers VALUES (NULL);
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
INSERT INTO numbers SELECT NULL FROM numbers;
以上填充值 1..1024
现在查询:
SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX(ExtractValue(@XML, '/As/A/B'), ' ', n), ' ', -1) AS value
FROM
numbers
WHERE
n BETWEEN 1 AND ExtractValue(@XML, 'count(/As/A/B)')
;
+-------+
| value |
+-------+
| Chan |
| Shey |
| Bob |
+-------+
3 rows in set (0.02 sec)
我们使用3ExtractValue(@XML, 'count(/As/A/B)')
来获取值——匹配的 XML 元素的数量。
遍历数字 1、2、3,我们从 textCHAN SHEY BOB
中提取 token #1、token #2、token #3,并按空格分割。
笔记:
祝你好运!