examples for oracle ref cursors
TYPE return_cur IS REF CURSOR RETURN all_tables%ROWTYPE;
PROCEDURE child(p_return_rec OUT return_cur); PROCEDURE parent(p_NumRecs PLS_INTEGER); |
END strongly_typed;
/
CREATE OR REPLACE PACKAGE BODY strongly_typed IS
PROCEDURE child(p_return_rec OUT return_cur) IS BEGIN OPEN p_return_rec FOR SELECT * FROM all_tables; END child; |
PROCEDURE parent (p_NumRecs PLS_INTEGER) IS p_retcur return_cur; at_rec all_tables%ROWTYPE; BEGIN child(p_retcur); FOR i IN 1 .. p_NumRecs LOOP FETCH p_retcur INTO at_rec; dbms_output.put_line(at_rec.table_name || ' - ' || at_rec.tablespace_name || ' - ' || TO_CHAR(at_rec.initial_extent) || ' - ' || TO_CHAR(at_rec.next_extent)); END LOOP; END parent; |
END strongly_typed;
/
set serveroutput on
exec strongly_typed.parent(1)
exec strongly_typed.parent(8)
CREATE OR REPLACE PROCEDURE child (
p_NumRecs IN PLS_INTEGER,
p_return_cur OUT SYS_REFCURSOR)
IS
BEGIN
OPEN p_return_cur FOR
'SELECT * FROM all_tables WHERE rownum <= ' || p_NumRecs ;
END child;
/
CREATE OR REPLACE PROCEDURE parent (pNumRecs VARCHAR2) IS
p_retcur SYS_REFCURSOR;
at_rec all_tables%ROWTYPE;
BEGIN
child(pNumRecs, p_retcur);
FOR i IN 1 .. pNumRecs
LOOP
FETCH p_retcur
INTO at_rec;
dbms_output.put_line(at_rec.table_name ||
' - ' || at_rec.tablespace_name ||
' - ' || TO_CHAR(at_rec.initial_extent) ||
' - ' || TO_CHAR(at_rec.next_extent));
END LOOP;
END parent;
/
set serveroutput on
exec parent(1)
exec parent(17)
CREATE TABLE employees (
empid NUMBER(5),
empname VARCHAR2(30));
INSERT INTO employees (empid, empname) VALUES (1, 'Dan Morgan');
INSERT INTO employees (empid, empname) VALUES (2, 'Jack Cline');
INSERT INTO employees (empid, empname) VALUES (3, 'Caleb Small');
COMMIT;
CREATE OR REPLACE PROCEDURE pass_ref_cur(p_cursor SYS_REFCURSOR) IS TYPE array_t IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER; rec_array array_t; BEGIN FETCH p_cursor BULK COLLECT INTO rec_array; FOR i IN rec_array.FIRST .. rec_array.LAST LOOP dbms_output.put_line(rec_array(i)); END LOOP; END pass_ref_cur; / |
set serveroutput on
DECLARE
rec_array SYS_REFCURSOR;
BEGIN
OPEN rec_array FOR
'SELECT empname FROM employees';
pass_ref_cur(rec_array);
CLOSE rec_array;
END;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242290/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle:open_cursorsOracle
- Oracle檢視已被使用的open_cursors&session_cached_cursorsOracleSession
- How to find Current open Cursors in OracleOracle
- Oracle Reporting 7 - Model ExamplesOracle
- zt_oracle cursor_open cursors_session_cached_cursors管理及優化OracleSession優化
- simd examples
- open_cursors與session_cached_cursorsSession
- crewAI-examplesAI
- Execute to Parse% 及open_cursors,session_cached_cursorsSession
- ref
- gitglossary learning by examplesGit
- DBMS_REPAIR ExamplesAI
- Examples of Secondary IndexIndex
- 手工建立oracle示例資料庫schema (Database Examples 安裝)Oracle資料庫Database
- oracle index unique scan/index range scan和mysql range/const/ref/eq_ref的區別OracleIndexMySql
- 引數 session_cached_cursors 與 open_cursors詳解Session
- session_cached_cursorsSession
- Cursors and SQL Areas (99)SQL
- 修改open_cursors和session_cached_cursors的引數值Session
- Ten examples of git-archiveGitHive
- Oracle 11gR2 調整session_cached_cursors引數OracleSession
- 關於open_cursors和session_cached_cursors的引數值Session
- Monitoring Open and Cached Cursors
- vue --ref用法Vue
- ref屬性
- ref和reactiveReact
- Spring中ref local=""與ref bean=""的區別SpringBean
- "bare repository" learning by examples
- Spark2.0.0 Install And ExamplesSpark
- Java的StateMachine(二)More ExamplesJavaMac
- Rust 中 *、&、mut、&mut、ref、ref mut 的用法和區別Rust
- SESSION_CACHED_CURSORS詳解Session
- Monitoring Open and Cached Cursors(zt)
- 引數SESSION_CACHED_CURSORSSession
- session_cached_cursors的研究Session
- React ref的用法React
- 正確設定open_cursors和'session_cached_cursors' 可以減少sql解析SessionSQL
- The Art of Unit Testing: with examples in C#C#