0

I have SQL command something like this:

DEFINE item_id_variable
BEGIN
INSERT INTO items (name, value, status) 
    VALUES (myname, myvalue, mystatus) 
    RETURNING item_id INTO item_id_variable;

The table has auto-incrementing attribute item_id and it's value for the row I just added is in the item_id_variable. I trigger this with cursor.execute() and it works ok, but I need to read the value of "item_id_variable" into a python variable, so I can pass it further in the code. How do I do that??

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
Stabby
  • 109
  • 7

2 Answers2

0

Have you tried cursor.fetchall() (for example)?

Antonio Beamud
  • 2,281
  • 1
  • 15
  • 26
0

Read it How do I get the "id" after INSERT into MySQL database with Python?

You can get the last insert id by "SELECT last_insert_id()" or connection.insert_id()

Community
  • 1
  • 1
Melug
  • 1,023
  • 9
  • 14
  • SELECT last_insert_id() cx_Oracle.DatabaseError: ORA-00923: FROM keyword not found while expected ; Also tried: connection.insert_id() AttributeError: 'cx_Oracle.Connection' object has no attribute 'insert_id' – Stabby Oct 11 '11 at 12:48