- 最后登录
- 2023-8-16
- 在线时间
- 1686 小时
- 威望
- 2135
- 金钱
- 50532
- 注册时间
- 2011-10-12
- 阅读权限
- 200
- 帖子
- 5207
- 精华
- 39
- 积分
- 2135
- UID
- 2
|
2#
发表于 2012-6-28 19:53:35
1.
bulk collect 主要用在批量 填充 队列变量,对于INSET 一般建议用nologging +append 优化
例如:
Cur_Num number := DBMS_Sql.Open_Cursor();
rc Sys_Refcursor;
cursor e is select Employee_ID, First_Name, Last_Name
from Employees;
type Emps_t is table of e%rowtype;
Emps Emps_t;
begin
DBMS_Sql.Parse(
c=>Cur_Num, Language_Flag=>DBMS_Sql.Native, Statement=>
'select Employee_ID, First_Name, Last_Name
from Employees
where Department_ID = :d and Salary > :s and ...');
DBMS_Sql.Bind_Variable(Cur_Num, ':d', Department_ID);
DBMS_Sql.Bind_Variable(Cur_Num, ':s', Salary);
...
Dummy := DBMS_Sql.Execute(Cur_Num);
-- Switch to ref cursor and native dynamic SQL
rc := DBMS_Sql.To_Refcursor(Cur_Num);
fetch rc bulk collect into Emps;
close rc;
...
以上利用 bulk collect 批量填充了Emps这张PL/SQL 表
2.
An ORA-22813 when using BULK COLLECT is typically expected behavior indicating that you have exceeded the amount of free memory in the PGA. As collections are processed by PL/SQL they use the PGA to store their memory structures. Depending on the LIMIT size of the BULK COLLECT and additional processing of the collected data you may exceed the free memory of the PGA. While intuitively you may think that increasing the PGA memory and increasing the LIMIT size will increase performance, the following example shows you that this is not true in this case. So, by reviewing this example you should be able to strike a balance between a reasonable LIMIT size and the size of the PGA while maintaining a high level of performance using BULK COLLECT.
合理设置limit size确实可以 避免PGA overflow 避免出现ORA-22813 错误
[oracle@vrh8 ~]$ oerr ora 22813
22813, 00000, "operand value exceeds system limits"
// *Cause: Object or Collection value was too large. The size of the value
// might have exceeded 30k in a SORT context, or the size might be
// too big for available memory.
// *Action: Choose another value and retry the operation.
|
|