mysql将一个字符转换成多个字符_将分隔的字符串转换为mysql中的多个值
這被稱為
walking a string.這是一個如何使用提供的規范來做到這一點的示例:
您需要創建一個包含與字段長度1一樣多的整數的表.因此,如果字段的長度為255,則需要256條記錄,其中只包含0-255的單個數字.
int_table:
+---+
| i |
+---+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+---+
接下來,您將需要一個連接此表的查詢,并檢查該位置是否存在逗號. (我分別使用字段client和items調用了表legacy_table.)
select
legacy_table.client,
substring(
legacy_table.items,
int_table.i + 1,
if(
locate(',', legacy_table.items, int_table.i + 1) = 0,
length(legacy_table.items) + 1,
locate(',', legacy_table.items, int_table.i + 1)
) - (int_table.i + 1)
) as item
from legacy_table, int_table
where legacy_table.client = 'xyz001'
and int_table.i < length(legacy_table.items)
and (
(int_table.i = 0)
or (substring(legacy_table.items, int_table.i, 1) = ',')
)
它可能沒有足夠的效率讓你真正使用它,但我想我會把它作為一個例子,只是讓你知道什么是可用的.
總結
以上是生活随笔為你收集整理的mysql将一个字符转换成多个字符_将分隔的字符串转换为mysql中的多个值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlabrobert锐化_Matla
- 下一篇: python中如何将数字改成字符串_py