[cx-oracle-users] Followup: cx_oracle, returning insert id
Brought to you by:
atuining
From: kellie h. <kel...@ya...> - 2006-04-03 21:07:31
|
Hello, Thanks for your help so far. Now can you tell me how to pass the table name and columns to be updated to the execute statement? Thanks again. Kellie Hobbs --- Anthony Tuininga <ant...@gm...> wrote: > Sure. Its quite straightforward but not covered by the DB API. > > # this creates the bind variable for use by Oracle > idVar = 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 = idVar, > someValue = "SomeValue") > > # get the value after the statement is executed > id = 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 > language > > that extends applications into web and mobile media. Attend the > live webcast > > and join the prime developer group breaking into this new coding > territory! > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > > _______________________________________________ > > cx-oracle-users mailing list > > cx-...@li... > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting > language > that extends applications into web and mobile media. Attend the live > webcast > and join the prime developer group breaking into this new coding > territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642 > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |