/
ImplicitResults.py
49 lines (37 loc) · 1.42 KB
/
ImplicitResults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#------------------------------------------------------------------------------
# Copyright 2016, 2017, Oracle and/or its affiliates. All rights reserved.
#
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
#
# Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta,
# Canada. All rights reserved.
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# ImplicitResults.py
# This script demonstrates the use of the 12.1 feature that allows PL/SQL
# procedures to return result sets implicitly, without having to explicitly
# define them.
#------------------------------------------------------------------------------
from __future__ import print_function
import cx_Oracle
con = cx_Oracle.connect("cx_Oracle/dev@localhost/orcl")
cur = con.cursor()
# use PL/SQL block to return two cursors
cur.execute("""
declare
c1 sys_refcursor;
c2 sys_refcursor;
begin
open c1 for
select * from TestNumbers;
dbms_sql.return_result(c1);
open c2 for
select * from TestStrings;
dbms_sql.return_result(c2);
end;""")
# display results
for ix, resultSet in enumerate(cur.getimplicitresults()):
print("Result Set #" + str(ix + 1))
for row in resultSet:
print(row)
print()