易截截图软件、单文件、免安装、纯绿色、仅160KB

PL/SQL Best Practice On BULK COLLECT

On BULK COLLECT
By Steven Feuerstein Oracle ACE
Best practices for knowing your LIMIT and kicking %NOTFOUND
I have started using BULK COLLECT whenever I need to fetch large volumes of data. This has caused me some trouble with my DBA, however. He is complaining that although my programs might be running much faster, they are also consuming way too much memory. He refuses to approve them for a production rollout. What's a programmer to do?
The most important thing to remember when you learn about and start to take advantage of features such as BULK COLLECT is that there is no free lunch. There is almost always a trade-off to be made somewhere. The tradeoff with BULK COLLECT, like so many other performance-enhancing features, is "run faster but consume more memory."
Specifically, memory for collections is stored in the program global area (PGA), not the system global area (SGA). SGA memory is shared by all sessions connected to Oracle Database, but PGA memory is allocated for each session. Thus, if a program requires 5MB of memory to populate a collection and there are 100 simultaneous connections, that program causes the consumption of 500MB of PGA memory, in addition to the memory allocated to the SGA.
Fortunately, PL/SQL makes it easy for developers to control the amount of memory used in a BULK COLLECT operation by using the LIMIT clause.
Suppose I need to retrieve all the rows from the employees table and then perform some compensation analysis on each row. I can use BULK COLLECT as follows:
PROCEDURE process_all_rows
IS
   TYPE employees_aat
   IS TABLE OF employees%ROWTYPE
      INDEX BY PLS_INTEGER;
   l_employees employees_aat;
BEGIN
   SELECT *
   BULK COLLECT INTO l_employees
      from employees;
   FOR indx IN 1 .. l_employees.COUNT
 &nbs


相关文档:

几个删除重复记录的SQL语句

比如现在有一人员表  (表名:peosons)
若想将姓名、身份证号、住址这三个字段完全相同的记录查询出来
select   p1.*   from   persons   p1,persons   p2   where   p1.id<>p2.id   and   p1.cardid &nbs ......

SQL 2008 清除日志文件

右击要清除日志的数据库 选择属性 
  
在数据库属性中 选择选项 在右边恢复模式下拉列表框中 选择简单 单击确定 返回 
  
右击要清除日志的数据库 选择任务-收缩-数据库 单击确定 
  
完成收缩 日志文件大小变为0  ......

sql 查询慢的48个原因分析

查询速度慢的原因很多,常见如下几种:
  1、没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷)
  2、I/O吞吐量小,形成了瓶颈效应。
  3、没有创建计算列导致查询不优化。
  4、内存不足
  5、网络速度慢
  6、查询出的数据量过大(可以采用多次查询,其他的方法降低数据量)
  7、 ......

SQL子查询实例

子查询是在一个查询内的查询。子查询的结果被DBMS使用来决定包含这个子查询的高级查询的结果。在子查询的最简单的形式中,子查询呈现在另一条SQL语句的WHERE或HAVING子局内。 
    列出其销售目标超过各个销售人员定额综合的销售点。
SELECT CITY
from OFFICES
WHERE TARGET&nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号