oracle 记录超过1000条,使用in方法
在oracle中,我们使用in方法查询记录的时候,如果in后面的参数个数超过1000个,那么会发生错误,下面的这个方法就是解决这个问题的,它将我们的上千个参数分成几组,保证每组的参数个数不超过1000
/**
* 生成符合条件的sql语句,解决in问题
* @param sqlParam:我们需要处理的参数的字符串格式,例如 1,2,3,4,5 参数以“,”隔开
* @param columnName:数据库中匹配的字段 比如,你想查看 id in(1,2,3),那么columnName 为id
* @return
*/
public static String getSqlIn( String sqlParam, String columnName ){
int buff_length = 0;
int spIndex = 500;
if(sqlParam==null || "".equals(sqlParam)){
return "";
}
String[] str_arr = sqlParam.split(",");
int width = str_arr.length;
int arr_width = width/spIndex;
if(width%spIndex!=0){
arr_width += 1;
}
StringBuffer buffer = new StringBuffer("");
for(int i=0;i<arr_width;i++){
buffer.append(" " + columnName + " IN(");
for(int j=i*spIndex,k=0;j<width && k<spIndex;j++,k++){
buffer.append("'" + str_arr[j] + "',");
}
buff_length = buffer.length();
buffer = buffer.delete(buff_length-1, buff_length).append(") OR");
}
return buffer.substring(0, buffer.length()-2);
}
相关文档:
Introduction to Schema Objects
A schema is a collection of logical structures of data, or schema objects. A schema is owned by a database user and has the same name as that user. Each user owns a single schema. Schema objects can be created and manipulated with SQL and include the following types o ......
MYSQL/MSSQL/ORACLE数据库脚本代码 收藏
/******************************************************************************/
/*
主流数据库MYSQL/MSSQL/ORACLE测试数据库脚本代码
脚本任务:建立4个表,添加主键,外键,插入数据,建立视图
运行环境1:microsoft sqlserver 2000 查询分析器
运行环境2:mysql5.0 p ......
<!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;
mso-font-charset:2;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:0 268435456 0 0 -2147483648 0;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 ......
DECODE函数是ORACLE PL/SQL是功能强大的函数之一,目前还只有ORACLE公司的SQL提供了此函数,其他数据库厂商的SQL实现还没有此功能。DECODE有什么用途呢? 先构造一个例子,假设我们想给智星职员加工资,其标准是:工资在8000元以下的将加20%;工资在8000元以上的加15%,通常的做法是,先选出记录中的工资字段值? select s ......