`
samttsch
  • 浏览: 63007 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

oracle 存储过程调优小结

 
阅读更多
1.对于分区表中的数据,直接删除掉分区表,alter table table_name drop partition partition_name; 因为分区表的分区相当于一个独立的表,删除分区相当于直接删除一个表速度快。

2.在删除大量数据时,批量删除,使用rownum一次只删除一部分,这样删除的语句可能存在一个循环,如:有多个表,每个表每次删除1000条数据,这样会存在一个问题,当只有一个表中有数据需要删除时,删除其他表的sql其实是多余的
解决方法:使用数组来保存上次删除的条数(sql%count),这样如果一个表中没有需要删除的数据,下次执行sql时不会再执行

3.对于多个sql中相同的部分的结果可以提取出来放到临时表中
如:delete * from memeber where groupid in (select id from group where valid=1 and time < sysdate);
可以将数据保存在一个临时表:

create global temporary table temp_test(id varchar2(15)) on commit preserve rows;(preserve表示在commit时保存数据,这样可以跨越多个事务,即提交不会清空临时表)

insert into temp_test (select id from group where valid=1 and time < sysdate);

在使用到的地方,用 (select id from temp_test )来代替.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics