怎么用python 连接数据库 执行select ID1 from table1 然后将ID1 传出来 给第二个SELECT 用:
答案:4 悬赏:80 手机版
解决时间 2021-03-19 13:33
- 提问者网友:谁的错
- 2021-03-19 02:56
怎么用python 连接数据库 执行select ID1 from table1 然后将ID1 传出来 给第二个SELECt 用: select ID2 from table2 where ID = ID1
最佳答案
- 五星知识达人网友:醉吻情书
- 2021-03-19 04:20
import cx_Oracle
dsn_tns = cx_Oracle.makedsn(ip,port,SID)
connection = cx_Oracle.connect(username,password,dsn_tns)
cursor = connection.cursor()
cursor.execute("select ID1 from table1")
id1list = [r[0] for r in cursor]
for id1 in id1list:
print '-'*4, id1, '-‘*16
cursor.execute("select ID2 from table2 where ID = %s", id1))
for r in cursor:
print r
dsn_tns = cx_Oracle.makedsn(ip,port,SID)
connection = cx_Oracle.connect(username,password,dsn_tns)
cursor = connection.cursor()
cursor.execute("select ID1 from table1")
id1list = [r[0] for r in cursor]
for id1 in id1list:
print '-'*4, id1, '-‘*16
cursor.execute("select ID2 from table2 where ID = %s", id1))
for r in cursor:
print r
全部回答
- 1楼网友:迟山
- 2021-03-19 07:21
search `pymysql` may help you
- 2楼网友:想偏头吻你
- 2021-03-19 07:06
安装模块 pymysql
- 3楼网友:神也偏爱
- 2021-03-19 05:34
import cx_Oracle
dsn_tns = cx_Oracle.makedsn(ip,port,SID)
connection = cx_Oracle.connect(username,password,dsn_tns)
cursor = connection.cursor()
ID1 = cursor.execute("select ID1 from table1")
ID2 = cursor.execute("select ID2 from table2 where ID = %s"%(ID1))
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯