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 ......
当我们获取数据时,可能会有这样的需求,即每次从表中获取数据时,是随机获取一定的记录,而不是每次都获取一样的数据,这时我们可以采取Oracle内部一些函数,来达到这样的目的.
1) select * from (select * from tablename order  ......
The following are number examples for the to_char
function.
to_char
(1210.73,
'9999.9')
would return '1210.7'
to_char
(1210.73,
'9,999.99')
would return '1,210.73'
to_char
(1210.73,
'$9,999.00')
would return
'$1,210.73'
to_char
(21,
'000099')
would return '000021'
The foll ......
一. 死锁的检测
--查死锁的会话。
select A.sid, b.serial#,
decode(A.type,
'MR', 'Media Recovery',
'RT','Redo Thread',
'UN','User Name',
'TX', 'Transaction',
'TM', ' ......
1.使用sqlldr
2.首先建立相应的表
create table test(ip1 number, ip2 number, locate varchar2(512),country varchar2(60),province varchar2(60),city varchar2(60))
3.写控制文件 city.ctl
load data
infile 'c:\city.txt'
append into table test
--when country='中国'
fields terminated by ','
(
ip1,
ip ......