场景
我传入in的范围是一个数组,里面值的类型为int64型,例如如下:
idSlice := []int{1, 2, 3, 4, 5, 6, 7}
正常的sql语句是这样写的:
select * from...table where id in (1, 2, 3, 4, 5, 6, 7);
于是我想当然的也在代码这样写:
idSlice := []int{1, 2, 3, 4, 5, 6, 7}
query...:= fmt.Sprintf("select * from table where id in (?)"...//这里填入的s必须要为string类型的数组,所以前面要转换成string类型
//此时的ss为:1','2','3','4','5','6','7
query := fmt.Sprintf("select...)
ss += s
} else {
s := fmt.Sprintf(",'%d'", idSlice[i])
ss += s
}
}
query := fmt.Sprintf("select