Added sample demonstrating the use of REF cursors.

This commit is contained in:
Anthony Tuininga 2018-05-18 14:25:20 -06:00
parent 52f4e7090c
commit 7b2195c37c
2 changed files with 44 additions and 0 deletions

31
samples/RefCursor.py Normal file
View File

@ -0,0 +1,31 @@
#------------------------------------------------------------------------------
# Copyright 2018, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# RefCursor.py
# Demonstrates the use of REF cursors with cx_Oracle.
#------------------------------------------------------------------------------
from __future__ import print_function
import cx_Oracle
import SampleEnv
connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING)
cursor = connection.cursor()
refCursor = connection.cursor()
cursor.callproc("myrefcursorproc", (2, 6, refCursor))
print("Rows between 2 and 6:")
for row in refCursor:
print(row)
print()
refCursor = connection.cursor()
cursor.callproc("myrefcursorproc", (8, 9, refCursor))
print("Rows between 8 and 9:")
for row in refCursor:
print(row)
print()

View File

@ -257,6 +257,19 @@ begin
end; end;
/ /
create or replace procedure &main_user..myrefcursorproc (
a_StartingValue number,
a_EndingValue number,
a_RefCursor out sys_refcursor
) as
begin
open a_RefCursor for
select *
from TestStrings
where IntCol between a_StartingValue and a_EndingValue;
end;
/
-- --
-- Create package for demoing PL/SQL collections and records. -- Create package for demoing PL/SQL collections and records.