Oacle 검색 을 해결 할 때 in 이 1000 이상 인 방법

/**
 * <b>function:</b>   oracle sql   in   (where id in (1, 2, ..., 1000, 1001)),
 *        1000     。
 *     oracle          。
 *         ,    where id (1, 2, ..., 1000) or id (1001, ...)
 * @author hoojo
 * @createDate 2012-8-31   02:36:03
 * @param ids in        
 * @param count in          
 * @param field in            
 * @return    field in (...) or field in (...)    
 */ 
private String getOracleSQLIn(List<?> ids, int count, String field) { 
    count = Math.min(count, 1000); 
    int len = ids.size(); 
    int size = len % count; 
    if (size == 0) { 
        size = len / count; 
    } else { 
        size = (len / count) + 1; 
    } 
    StringBuilder builder = new StringBuilder(); 
    for (int i = 0; i < size; i++) { 
        int fromIndex = i * count; 
        int toIndex = Math.min(fromIndex + count, len); 
        //System.out.println(ids.subList(fromIndex, toIndex)); 
        String productId = StringUtils.defaultIfEmpty(StringUtils.join(ids.subList(fromIndex, toIndex), "','"), ""); 
        if (i != 0) { 
            builder.append(" or "); 
        } 
        builder.append(field).append(" in ('").append(productId).append("')"); 
    } 
        
    return StringUtils.defaultIfEmpty(builder.toString(), field + " in ('')"); 
}

좋은 웹페이지 즐겨찾기