日期:2014-05-16  浏览次数:20555 次

Oracle应用技巧
(1)oracle数据库中in中最多1000个元素限制:
select * from a where id in (1,2,.....1001);会报错,报in中的元素不能超过1000个。
select * from a where id in (select id from b where rownum < 6002);该语句不会报错,正常运行。
对其中的原理,我不是很明白。

(2)一条语句删除表中重复记录(一个或多个列重复):
delete from TABLENAME where rowid not in
       (select max(rowid) from TABLENAME group by (COL1,COL2,COL3....COLn);

(3)按日期条件查询某一天的记录:
select * from TABLENMAE
where createTime >= to_date(:date, 'YYYY-MM-DD')
   and createTime < to_date(:date, 'YYYY-MM-DD') + 1

(4)分页查询时一定记得要按唯一键排序,否则会莫名其妙的发生某些记录串页的情况:
select *
  from (select a.*, rownum row_num from tableName a order by a.uniqueColumn)
where row_num <= 100
   and row_num > 80