Re: [cx-oracle-users] cx_oracle, returning insert id
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2006-03-22 20:45:52
|
Sure. Its quite straightforward but not covered by the DB API. # this creates the bind variable for use by Oracle idVar =3D cursor.var(cx_Oracle.NUMBER) # execute the statement exactly as you normally would, # binding the variable you just created above cursor.execute(""" insert into SomeTable ( SomeOtherColumn ) values ( :someValue ) returning Id into :id""", id =3D idVar, someValue =3D "SomeValue") # get the value after the statement is executed id =3D idVar.getvalue() Hope that explains things. On 3/22/06, kellie hobbs <kel...@ya...> wrote: > Hello, > > I am trying to get back the id of a record after inserting it into the > table. My Oracle database has a trigger that automatically creates the > id on insert. The PL/SQL statement that works for me is: > SQL> declare id int; > 2 begin > 3 insert into table (field) values ('foo') returning tableid into > id; > 4 dbms_output.put_line(id); > 5 end; > 6 / > > How can I run this through cx_oracle and get the id stored in a > variable so I can use it? > > Many thanks. > > Kellie Hobbs, UC Berkeley > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting langua= ge > that extends applications into web and mobile media. Attend the live webc= ast > and join the prime developer group breaking into this new coding territor= y! > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat= =3D121642 > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |