About Cursor

Cursors


  Each SQL statement is associated with a cursor. The cursor is a data structure that keeps track of all data that is needed to process the statement. 

Explicit cursors

In PL/SQL, all SQL statements except the select statement create an implicit cursor. That is: the cursor is not explicitely declared. For select statements, an explicit cursor can be declared. Such an explicit cursor can be thought of as a pointer to a record in a table or record set that can be moved forward within this table or record set.
An explit cursor is declared and used, for example, like so:
declare

  cursor explic_cur is 
       select table_name
         from user_tables;

begin

  for r in explic_cur loop
    dbms_output.put_line(r.table_name);
  end loop;

end;
/
Note: not all select statements in PL/SQL are explicit. For example, the following creates in implicit cursor:
declare
  cnt number;
begin
  select count(*) into cnt
    from user_tables;

  dbms_output.put_line(
   'There are ' || cnt || ' tables in your schema'
  );
end;
/

Memory

A cursor "points" into the shared pool where its parsed sql statement is stored. A cursor also occupies memory in the pga to store the values of bind variables and to keep information about the cursor's state (open, bound, executed, closed).

Open cursors

A cursor being open means that its associated statement is in the sql area. Parsing is not necessary for such cursors.

Cached cursors

The initialization parameter session_cached_cursors specifies how many cursors are held open for a session. Such cached cursors are stored in the session cursor cache.
If a new cursor needs to me moved into the session cursor cache, the cursor that hasn't been used for the longest time will be removed from the session cursor cache.
The higher the value of session_cached_cursors is set to a high value, the more the shared pool might become fragmented.

Links

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值