diff --git a/samples/RefCursor.py b/samples/RefCursor.py new file mode 100644 index 0000000..734fbdc --- /dev/null +++ b/samples/RefCursor.py @@ -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() + diff --git a/samples/sql/SetupSamples.sql b/samples/sql/SetupSamples.sql index e1fd11f..68e00e4 100644 --- a/samples/sql/SetupSamples.sql +++ b/samples/sql/SetupSamples.sql @@ -257,6 +257,19 @@ begin 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.