将逗号分隔值插入SQL

时间:2022-01-13 21:50:46

I would like to take a list that I have in a text file, of values which are separated by commas:

我想在文本文件中列出一个由逗号分隔的值的列表:

Example - 1,2,3,4,5,6,7,8,9,0

示例 - 1,2,3,4,5,6,7,8,9,0

then put the values in a database table(I'm going to use this table for auto-complete with jQuery).

然后将值放在数据库表中(我将使用此表与jQuery自动完成)。

I would have done an array for the auto-complete but I have something like 1000 values so I think its better to pull from SQL(am i right?)

我会为自动完成做一个数组,但我有1000个值,所以我认为最好从SQL中取出(我是对的吗?)

Try to explain it to me slowly cause I'm a novice and this is so confusing :)

试着向我慢慢解释一下,因为我是新手,这太令人困惑了:)

1 个解决方案

#1


2  

If those are 1000 constant values (like countries), put them in array.
If they are fairly dynamic, put them in a table
Assuming the table is called T1 and has one field F1, you need to transform the string 1,2,3,4,5,6,7,8....N to

如果这些是1000个常量值(如国家/地区),请将它们放在数组中。如果它们是相当动态的,将它们放在一个表中假设该表被称为T1并且有一个字段F1,则需要将字符串1,2,3,4,5,6,7,8 .... N转换为

INSERT INTO T1
VALUES (1),(2),(3),(4),(5),(6),(7),(8)......(N);

#1


2  

If those are 1000 constant values (like countries), put them in array.
If they are fairly dynamic, put them in a table
Assuming the table is called T1 and has one field F1, you need to transform the string 1,2,3,4,5,6,7,8....N to

如果这些是1000个常量值(如国家/地区),请将它们放在数组中。如果它们是相当动态的,将它们放在一个表中假设该表被称为T1并且有一个字段F1,则需要将字符串1,2,3,4,5,6,7,8 .... N转换为

INSERT INTO T1
VALUES (1),(2),(3),(4),(5),(6),(7),(8)......(N);