`
xiemingmei
  • 浏览: 207387 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics