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
相关文档:
一般的远程访问的写成这样:
Data Source=IP;Initial Catalog=数据库名;UserID=用户名;Password=密码
本地访问的写成这样:
Data Source=(local);Initial Catalog=数据库名;UserID=用户名;Password=密码
如果是本地的,通过windows组件验证的(也就是没有用户名,密码的)写成这样:
Data Source=(local);Initial Cata ......
用TSQL把Access的表导入到远程Sql Server:
把access 的.mdb里t_itemList 表的数据插入到远程SqlServer的t_itemL1111111表里。
SELECT top 10 * INTO t_itemL1111111 IN [ODBC]
[ODBC;Driver=SQL Server; UID=jyb;PWD=jyb;Server=10.1.18.49;DataBase=所有合并;]
&nb ......
SQL Server 2005 CE开发环境介绍:
最近学习使用SQL Server 2005 Compact Edition进行数据存储,在学习的过程中发现,使用SQL Server2005 management Studio创建数据库时,在“服务器类型”下拉列表中没有“SQL Server Compact Edition”选项。因为文章 ......
子查询是在一个查询内的查询。子查询的结果被DBMS使用来决定包含这个子查询的高级查询的结果。在子查询的最简单的形式中,子查询呈现在另一条SQL语句的WHERE或HAVING子局内。
列出其销售目标超过各个销售人员定额综合的销售点。
SELECT CITY
from OFFICES
WHERE TARGET&nbs ......
基于索引的SQL语句优化之降龙十八掌
1 前言
客服业务受到SQL语句的影响非常大,在规模比较大的局点,往往因为一个小的SQL语句不够优化,导致数据库性能急剧下降,小型机idle所剩无几,应用服务器断连、超时,严重影响业务的正常运行。因此,称低效的SQL语句为客服业务的 ......