java支持ORACLE的in不能超过1000

Oracle的in语句,不能超过1000个值,否则会报sql出错。

public String splitInCondition(List dataList, String columnName, String type)
    {

        String relation = null;
        if ("in".equalsIgnoreCase(type))
        {
            relation = " OR ";
        }
        else
        {
            relation = " AND ";
        }

        // 需要返回的sql的in子语句
        StringBuilder sqlBuilder = new StringBuilder("(" + columnName + " " + type + " (");

        // 列表长度
        int dataSize = dataList.size();

        int count = 0;

        while (count < dataSize)
        {
            if ((count + 1) % 1000 == 0)
            {
                sqlBuilder.deleteCharAt(sqlBuilder.lastIndexOf(","));

                sqlBuilder.append(") " + relation + " " + columnName + " " + type + " (");
            }

            sqlBuilder.append('\'');
            sqlBuilder.append(dataList.get(count));
            sqlBuilder.append('\'');
            sqlBuilder.append(',');
            count++;
        }

        // 删除最后一个,
        sqlBuilder.deleteCharAt(sqlBuilder.lastIndexOf(","));

        // 添加右括号
        sqlBuilder.append(')');
        sqlBuilder.append(')');

        return sqlBuilder.toString();
    }

 

你可能感兴趣的:(java支持ORACLE的in不能超过1000)