【发布时间】:2022-07-28 08:22:20
【问题描述】:
在我的 python 代码中,我将一个值插入到一个表中。
在表中,有一个序列会自动分配一个ID。
插入后,我想把它放回我的 python 应用程序:
import cx_Oracle, sys
with cx_Oracle.connect(user=ORA_USER,password=ORA_PWD,dsn=ORA_DSN) as conn:
with conn.cursor() as cur:
cur.execute("Insert into my_table columns(data) values ('Hello')")
conn.commit()
with cx_Oracle.connect(user=ORA_USER,password=ORA_PWD,dsn=ORA_DSN) as conn:
with conn.cursor() as cur:
r = cur.execute("select id from my_table where data = 'Hello'")
print(r)
if r is None:
print("Cannot retrieve ID")
sys.exit()
不幸的是,结果集r 始终为“无”,即使该值已正确插入(通过 sqldeveloper 检查)。
我做错了什么? 我什至打开了一个新连接,以确保获得价值......
【问题讨论】: