C#-指定した項目数で配列を分割し、oracle in式パラメータは最大1000個の代替案をサポートする
C#–指定した項目数で配列を分割し、oracle in式パラメータは最大1000個の代替案c#-配列を分割する最適な方法をサポートする[閉じる]
以下は、プロジェクト数1200のデジタルitemsに対して、100個当たりのプロジェクト数を1組に分割し、パケットを2桁のデジタルchunksで格納した配列である.
出力結果表示:IDEオンライン
インスタンステスト:IDEオンライン
C#指定項目数で配列を分割
以下は、プロジェクト数1200のデジタルitemsに対して、100個当たりのプロジェクト数を1組に分割し、パケットを2桁のデジタルchunksで格納した配列である.
出力結果表示:IDEオンライン
using System;
using System.Linq;
public class Test
{
public static void Main()
{
// 1200
string[] items = Enumerable.Range(1, 1200).Select(i => "Item" + i).ToArray();
// 100 。 items index/100 。
String[][] chunks = items
.Select((s, i) => new { Value = s, Index = i })
.GroupBy(x => x.Index / 100)
.Select(grp => grp.Select(x => x.Value).ToArray())
.ToArray();
for (int i = 0; i < chunks.Length; i++)
{
foreach (var item in chunks[i])
Console.WriteLine("chunk:{0} {1}", i, item);
}
}
}
インスタンス適用:oracle in式パラメータは最大1000個の代替案をサポートし、1000個ごとに1個のinに配置する。
インスタンステスト:IDEオンライン
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
string sqlInCol = "ima01 in ";
//string[] dataList = System.IO.File.ReadAllLines( "../../../DataList.txt");
string[] dataList ={
"220000004754",
"220000004755",
"220000004814",
"220000004817",
"220000004836",
"220000004877",
"220000004878",
"220000004879",
"220000004980",
"220000004984",
"220000004988"
};
String[] chunks = dataList
.Select((s, i) => new { Value = s, Index = i })
.GroupBy(x => x.Index / 2)// 2 。
.Select(grp => ($"( '{string.Join("','", grp.Select(x => x.Value).ToArray())}' )\r
"))
.ToArray();
string sqlIn = sqlInCol +string.Join($"or {sqlInCol }", chunks);
Console.WriteLine(sqlIn);
Console.ReadLine();
}
}