[size=medium][color=red][b]描述:
通过Excel导入数据,解析后放入list集合中,集合中数据的顺序和excel导入时的一致,通过批量添加到数据库中,出现的结果是数据库中的数据是无序的(也就是和excel导入时的顺序不一致).
求解...[/b][/color][/size]
I have met the same issue before in Oracle, but I also don't know how come the the physics orders of data changed while bulk insert.
I prompted the issue to stackoverflow, and one expert replied me:
[quote]
A heap organized table is inherently unordered. Unless your query specifies an ORDER BY clause, Oracle is free to return data in whatever order it chooses. And it is free to physically store data in any order regardless of the order of inserts.
[/quote]
So I think you have two options:
[list]
[*] Give up bulk insert, and commit record one by one
[*] Add a serial number in your excel, and after importing ,use
[code="SQL"]
SELECT serial_number, name
FROM your_table_name
ORDER BY serial_number
[/code]
to get the data
[/list]
Do you use Oracle db ?