Difference between cursor and a ref cursor
technically, under the covers, at the most "basic level", they are the same.
A "normal" plsql cursor is static in defintion.
Ref cursors may be dynamically opened or opened based on logic.
Declare
type rc is ref cursor;
cursor c is select * from dual;
l_cursor rc;
begin
if ( to_char(sysdate,'dd') = 30 ) then
open l_cursor for 'select * from emp';
elsif ( to_char(sysdate,'dd') = 29 ) then
open l_cursor for select * from dept;
else
open l_cursor for select * from dual;
end if;
open c;
end;
/
Given that block of code -- you see perhaps the most "salient" difference -- no
matter how many times you run that block -- cursor C will always be select *
from dual. The ref cursor can be anything.
Another difference is a ref cursor can be returned to a client. a plsql "cursor
cursor" cannot be returned to a client.
Another difference is a cursor can be global -- a ref cursor cannot (you cannot
define them OUTSIDE of a procedure / function)
Another difference is a ref cursor can be passed from subroutine to subroutine
-- a cursor cannot be.
Another difference is that static sql (not using a ref cursor) is much more
efficient then using ref cursors and that use of ref cursors should be limited
to
- returning result sets to clients
- when there is NO other efficient/effective means of achieving the goal
that is, you want to use static SQL (with implicit cursors really) first and use
a ref cursor only when you absolutely have to
A "normal" plsql cursor is static in defintion.
Ref cursors may be dynamically opened or opened based on logic.
Declare
type rc is ref cursor;
cursor c is select * from dual;
l_cursor rc;
begin
if ( to_char(sysdate,'dd') = 30 ) then
open l_cursor for 'select * from emp';
elsif ( to_char(sysdate,'dd') = 29 ) then
open l_cursor for select * from dept;
else
open l_cursor for select * from dual;
end if;
open c;
end;
/
Given that block of code -- you see perhaps the most "salient" difference -- no
matter how many times you run that block -- cursor C will always be select *
from dual. The ref cursor can be anything.
Another difference is a ref cursor can be returned to a client. a plsql "cursor
cursor" cannot be returned to a client.
Another difference is a cursor can be global -- a ref cursor cannot (you cannot
define them OUTSIDE of a procedure / function)
Another difference is a ref cursor can be passed from subroutine to subroutine
-- a cursor cannot be.
Another difference is that static sql (not using a ref cursor) is much more
efficient then using ref cursors and that use of ref cursors should be limited
to
- returning result sets to clients
- when there is NO other efficient/effective means of achieving the goal
that is, you want to use static SQL (with implicit cursors really) first and use
a ref cursor only when you absolutely have to
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242289/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- What is the difference between a Homemaker and a Housewife?
- 【CURSOR】Oracle 遊標 (cursor)知識梳理Oracle
- Cursor使用
- Oracle CursorOracle
- Postgresql的CURSOR SHARINGSQL
- Oracle:cursor:mutex XOracleMutex
- firefox css cursor handFirefoxCSS
- Difference Between Arraylist And Vector : Core Java Interview Collection QuestionJavaView
- 提點效: 使用 Cursor
- CSS滑鼠樣式(cursor)CSS
- cursor pin S wait on XAI
- cursor: pin S wait on XAI
- 哈哈,我好像知道 Cursor 為什麼叫 Cursor 了,真相竟然是。。。
- 【CURSOR】Oracle 子游標無法共享的原因之V$SQL_SHARED_CURSOROracleSQL
- [20201111]CURSOR_SPACE_FOR_TIME.txt
- MySQL的多層SP中Cursor的m_max_cursor_index相關BUG分析MySqlIndex
- 像VS Code一樣,設定"用Cursor開啟" / 為Cursor新增右鍵選單
- IDE AI- vscode / cursor / openfuse ideIDEAIVSCode
- Cursor Cache Hit Ratio超過100%
- div新增cursor:pointer;失效問題。
- Adaptive Cursor Sharing(第五篇)APT
- Adaptive Cursor Sharing(第三篇)APT
- Adaptive Cursor Sharing(第四篇)APT
- [20180803]cursor_sharing = force.txt
- Adaptive Cursor Sharing(第二篇)APT
- Difference between Microsoft Dynamics 365 WEB API, Organization Service and Organization Data ServicROSWebAPI
- [20221227]Adaptive Cursor Sharing & 直方圖.txtAPT直方圖
- cursor:pin S wait on X故障診分析AI
- flask-sqlalchemy中使用cursor遊標FlaskSQL
- [20201117]解析cursor pin S等待事件.txt事件
- [20202117]Function based indexes and cursor sharing.txtFunctionIndex
- Adaptive Cursor Sharing (第一篇)APT
- 使用 OPEN CURSOR 和 FETCH NEXT CURSOR 對 SAP 資料庫表進行分塊讀寫試讀版資料庫
- 說下你對cursor屬性的理解
- Cursor AI應用一些建議AI
- Cursor Pro for mac(滑鼠指標放大工具)Mac指標
- Cursor Mutex S Waits等待事件引發hangMutexAI事件
- ORACLE中Cursor_sharing引數詳解Oracle