Godzilla escribió:
On May 11, 11:51 am, Godzilla <[EMAIL PROTECTED]> wrote:
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 function via the
callfunc method. Can anyone help?
I also tried the execute(), and callproc(), but to no avail. My
function is as below:
create or replace function addRow(desc table1.col1%type) return number
is id number;
begin
insert into table1 (description) values (desc) returning table1ID
into id;
return(id);
exception
when others then return(-1)
end;
The code in the callfunc:
cur.callfunc("addRow", returnType, param)
Question is:
- What is returnType and how to I declare that before passing into the
function?
- How do I define the parameters?
I tried the setinputsizes and setoutputsize, but I keep getting errors
saying the parameter is incorrectly defined. Please help. Thank.
Hello,
found a solution in another thread... see
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ab13d3364aafdd28/4ca1fde2069ff3da?lnk=st&q=cx_oracle+how+to+setinputsizes&rnum=9&hl=en#4ca1fde2069ff3da
for more info.
Thanks.
Did you mean A. Tuininga's suggestion dated Sep 13 2002?
cx_Oracle improved since then.
Maybe I fail to understand the problem but the following code looks like
valid anwer for what you asked:
create table test1 (id1 number, id2 varchar2(600));
create sequence testseq;
create or replace function functest(texto in test1.id2%type)
return number
is
output number;
begin
insert into test1 (id1, id2) values (testseq.nextval, texto)
returning id1 into output;
commit work;
return output;
end functest;
/
>>> import cx_Oracle as ora
>>> con = ora.connect('myuser', 'qwerty', 'orcl')
>>> cur = con.cursor()
>>> val = 0
>>> cur.callfunc("functest", val, ['this is a test'])
'1'
>>> cur.callfunc("functest", val, ['this is a test'])
'2'
>>> cur.callfunc("functest", val, ['this is a test'])
'3'
>>> cur.callfunc("functest", val, ['this is a test'])
'4'
>>> cur.callfunc("functest", val, ['this is a test'])
'5'
>>> cur.callfunc("functest", val, ['this is a test'])
'6'
Cheers
--
http://mail.python.org/mailman/listinfo/python-list