Skip to content

Commit 7b2195c

Browse files
Added sample demonstrating the use of REF cursors.
1 parent 52f4e70 commit 7b2195c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

samples/RefCursor.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#------------------------------------------------------------------------------
2+
# Copyright 2018, Oracle and/or its affiliates. All rights reserved.
3+
#------------------------------------------------------------------------------
4+
5+
#------------------------------------------------------------------------------
6+
# RefCursor.py
7+
# Demonstrates the use of REF cursors with cx_Oracle.
8+
#------------------------------------------------------------------------------
9+
10+
from __future__ import print_function
11+
12+
import cx_Oracle
13+
import SampleEnv
14+
15+
connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING)
16+
cursor = connection.cursor()
17+
18+
refCursor = connection.cursor()
19+
cursor.callproc("myrefcursorproc", (2, 6, refCursor))
20+
print("Rows between 2 and 6:")
21+
for row in refCursor:
22+
print(row)
23+
print()
24+
25+
refCursor = connection.cursor()
26+
cursor.callproc("myrefcursorproc", (8, 9, refCursor))
27+
print("Rows between 8 and 9:")
28+
for row in refCursor:
29+
print(row)
30+
print()
31+

samples/sql/SetupSamples.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ begin
257257
end;
258258
/
259259

260+
create or replace procedure &main_user..myrefcursorproc (
261+
a_StartingValue number,
262+
a_EndingValue number,
263+
a_RefCursor out sys_refcursor
264+
) as
265+
begin
266+
open a_RefCursor for
267+
select *
268+
from TestStrings
269+
where IntCol between a_StartingValue and a_EndingValue;
270+
end;
271+
/
272+
260273

261274
--
262275
-- Create package for demoing PL/SQL collections and records.

0 commit comments

Comments
 (0)