0
我有以下字符串156,12,99,12,14,17有时候这会更长和/或更短,并涉及字母和数字,例如cc,21,366, DDD。Mysql按分隔符分割字符串(列)为新行
理想的输出是 output:
我有这个,给了我区划界定的数列:
select
LENGTH(a.column) - LENGTH(REPLACE(a.column, ',', '')) + 1 AS numberofdelimit
FROM <mydatabase>.<mytable> as a
where a.id = 4;
我也知道,这个代码将会给我划定的文字:
SUBSTRING_INDEX(a.column, ',', numbers.n)
我努力把它放在一起把值放入新行。
在'MySQL'中没有直接的做法。你可能必须编写'MySQL函数'才能做到这一点。使用这种用户定义的'mysql函数'有没有什么问题? – 1000111
一种选择是使用类似[common_schema](https://common-schema.googlecode.com/svn/trunk/common_schema/doc/html/introduction.html)的东西,特别是[split_token](https:// common -schema.googlecode.com/svn/trunk/common_schema/doc/html/split_token.html)和[get_num_tokens](https://common-schema.googlecode.com/svn/trunk/common_schema/doc/html/get_num_tokens。 HTML)。 – wchiquito