📜  隐式游标和显式游标的区别

📅  最后修改于: 2021-09-14 02:31:38             🧑  作者: Mango

ORACLE 等数据库有一个内存区域,在那里处理指令和获取的数据。游标是指向该区域的指针。包含在该内存区域中的数据也称为Active Set 。游标可以大致分为隐式游标显式游标

隐式游标和显式游标的区别:

Implicit Cursors Explicit Cursors
Implicit cursors are automatically created when select statements are executed. Explicit cursors needs to be defined explicitly by the user by providing a name.
They are capable of fetching a single row at a time. Explicit cursors can fetch multiple rows.
They are more vulnerable to errors such as Data errors, etc. They are less vulnerable to errors(Data errors etc.)
Provides less programmatic control to the users User/Programmer has the entire control.
Implicit cursors are less efficient. Comparitive to Implicit cursors, explicit cursors are more efficient.

Implicit Cursors are defined as: 
 

BEGIN
SELECT attr_name from table_name
where CONDITION;
END

 

Explicit cursors are defined as: 
 

DECLARE
CURSOR cur_name IS
SELECT attr_name from table_name 
where CONDITION;
BEGIN
...

 

Implicit cursors requires anonymous buffer memory for storage purpose. Explicit cursors use user-defined memory space for storage purpose
Cursor attributes use prefix “SQL”. 
Structure for implicit cursors: SQL%attr_name 
Few implicit cursors attributes are: SQL%FOUND, SQL%NOTFOUND, SQL%ROWCOUNT
Structure for explicit cursors: cur_name%attr_name 

Few explicit cursors are: cur_name%FOUND, cur_name%NOTFOUND, cur_name%ROWCOUNT