473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

cx_Oracle callproc output parameters

I have a stored procedure that has a single output parameter. Why do I
have to pass it a string big enough to hold the value it is to receive?
Why can't I pass an empty string or None?
import cx_Oracle as oracle
connection = oracle.connect('usr/pwd@tns')
cursor = connection.cursor()
network_name, = cursor.callproc('my_pkg.get_network_name_sp', ('',)) Traceback (most recent call last):
File "<interactive input>", line 1, in ?
DatabaseError: ORA-06502: PL/SQL: numeric or value error: character
string buffer too small
ORA-06512: at "USR.MY_PKG", line 35
ORA-06512: at line 1

The following works fine, but I don't like having to do it:
network_name, = cursor.callproc('my_pkg.get_network_name_sp', (' ' * 32,))


Am I missing something obvious here?

Nov 8 '05 #1
4 13319
infidel wrote:
I have a stored procedure that has a single output parameter. Why do I
have to pass it a string big enough to hold the value it is to receive?
Why can't I pass an empty string or None?

import cx_Oracle as oracle
connection = oracle.connect('usr/pwd@tns')
cursor = connection.cursor()
network_name, = cursor.callproc('my_pkg.get_network_name_sp', ('',))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
DatabaseError: ORA-06502: PL/SQL: numeric or value error: character
string buffer too small
ORA-06512: at "USR.MY_PKG", line 35
ORA-06512: at line 1

The following works fine, but I don't like having to do it:

network_name, = cursor.callproc('my_pkg.get_network_name_sp', (' ' * 32,))

Am I missing something obvious here?


Yes - where should the oracle store the data if you pass None
(null-pointer!) or a too short string? The C-Api of oracle requires an
INOUT-Paramter to be properly dimensioned - its like other c-calls, that
take a pointer and a size argument. Thus you don't have to deal with
freeing malloc'ed memory in the caller.

I'm not sure about it, but possibly a _return_-value might help here,
possible by using a function inbstead of a procedure. Did you try that?
Of course it would require to rewrite your procedure to be a function,
or if that is not possible due to others using it too, wrap it in a
p/sql function. I'm a bit rusty on p/sql, so I can't wirte it out of my
head.

Then you could e.g. do

select my_pkg.wrapped_get_network_name() from dual

and wouldn't have to care about sizes.

regards,

Diez

Nov 9 '05 #2
infidel wrote:
I have a stored procedure that has a single output parameter. Why do I
have to pass it a string big enough to hold the value it is to receive?
Why can't I pass an empty string or None?
[...]
Am I missing something obvious here?


You have to use variable objects to the callproc() that will hold the
output values. This is an example using three VARCHAR output parameters.

HTH,

-- Gerhard
import cx_Oracle

con = cx_Oracle.connect("user/password@my_conn")
cur = con.cursor()

l_SchemaName = cur.var(cx_Oracle.STRING)
l_DbName = cur.var(cx_Oracle.STRING)
l_DomainName = cur.var(cx_Oracle.STRING)

cur.callproc("TP_Lookup.GetSchema", (l_SchemaName, l_DbName, l_DomainName))

print "You are connected to",
print "the schema", l_SchemaName.getvalue(),
print "at %s.%s" % (l_DbName.getvalue(), l_DomainName.getvalue())

Nov 9 '05 #3

Gerhard Häring wrote:
You have to use variable objects to the callproc() that will hold the
output values. This is an example using three VARCHAR output parameters.


Oh boy, one never stops learning... I still thing a single in-out-value
is crying for a function - but in case of several parameters, this of
course is way more elegant as it requires no knowledge about the
column-size beforehand.

Regards,

Diez

Nov 9 '05 #4
Thanks!

On 11/9/05, Gerhard Häring <gh@ghaering.de> wrote:
infidel wrote:
I have a stored procedure that has a single output parameter. Why do I
have to pass it a string big enough to hold the value it is to receive?
Why can't I pass an empty string or None?
[...]
Am I missing something obvious here?


You have to use variable objects to the callproc() that will hold the
output values. This is an example using three VARCHAR output parameters.

HTH,

-- Gerhard
import cx_Oracle

con = cx_Oracle.connect("user/password@my_conn")
cur = con.cursor()

l_SchemaName = cur.var(cx_Oracle.STRING)
l_DbName = cur.var(cx_Oracle.STRING)
l_DomainName = cur.var(cx_Oracle.STRING)

cur.callproc("TP_Lookup.GetSchema", (l_SchemaName, l_DbName, l_DomainName))

print "You are connected to",
print "the schema", l_SchemaName.getvalue(),
print "at %s.%s" % (l_DbName.getvalue(), l_DomainName.getvalue())

Nov 9 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: GrayGeek | last post by:
After cx_Oracle and the related Oracle tools for Python 2.2.3 + Boa-constructor on Win2000, I added "import cx_Oracle" to the top of a test script. It gives me an error about being unable to find...
2
by: Mike Stenzler | last post by:
Does anyone have any sample code for the cx_Oracle library? www.computronix.com I have the doco and can connect and do simple ops against my database but I'm struggling with the correct syntax...
4
by: Harald Armin Massa | last post by:
Hello, I am looking for a method to convince cx_Oracle and oracle to encode it's replies in UTF8. For the moment I have to... cn=cx_Oracle.connect("user","password", "database")...
4
by: Richard Schulman | last post by:
I'm having trouble getting started using Python's cx_Oracle binding to Oracle XE. In forthcoming programs, I need to set variables within sql statements based on values read in from flat files. But...
0
by: JG | last post by:
Hi, I am using Python 2.4 and cx_Oracle. I have a stored proc that takes two arguments. First is an NUMBER, second is a BOOLEAN. How do you call that stored procedure? After properly...
1
by: Godzilla | last post by:
Hi all, I need to know how to use the method callfunc in cx_Oracle. I am trying to get a primary key after an insert via a function call, but I do not know how to pass the return value from the...
3
by: Benjamin Hell | last post by:
Hi! I have a problem with the cx_Oracle module (Oracle database access): On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g) I can get query results consisting of strings...
3
by: lukasz.f24 | last post by:
Hello, I'm trying to pass array as an argument into PL/SQL procedure. According to cursor manual (http://cx-oracle.sourceforge.net/html/ cursorobj.html) arrayvar() should be use to do it. I've...
0
by: Edwin.Madari | last post by:
gaius hammond Wrote: There is no mode parameter to connect. use try-catch around db = connect(mode=SYSDBA) line to see what's going on. Edwin The information contained in this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.