Added sample demonstrating the use of REF cursors.
This commit is contained in:
parent
52f4e7090c
commit
7b2195c37c
31
samples/RefCursor.py
Normal file
31
samples/RefCursor.py
Normal 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()
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user