Oracle数据库查询用 where in 查询的项超过1000条的解决方案
func GetWhereInValuesSql (column string, list []string, num int) string {
valueSize := len(list)
if valueSize == 0 {
return ""
}
sql := "("
add := 0
if valueSize%num != 0 {
add = 1
}
batchSize := valueSize/num + add
for i := 0; i < batchSize; i++ {
if i > 0 {
sql += ") or "
}
sql += column + " in ("
for j := i * num; (j < (i+1)*num) && j < valueSize; j++ {
if j > i*num {
sql += ","
}
sql += "'" + list[j] + "'"
}
}
sql += "))"
return sql
}
有疑问加站长微信联系(非本文作者))