db = cx_Oracle.connect(‘scxxt’, ‘xxt’, ‘localhost:1521/ora11g’);
cr = db.cursor(); # 创建cursor
try:
for info in infos:
try:
db.begin();
sumPreSelectSql = “select sum(mm.mark_value)-sum(mm.exchange_value) from mark_month mm where mm.user_mobile=:1 and mm.ec_code=:2”;
monthPreSelectSql = “select * from mark_month mm where mm.user_mobile=:1 and mm.ec_code=:2 “;
cr.execute(monthPreSelectSql,[info[2],info[0]]);
monthPreSelectR = cr.fetchall();
if len(monthPreSelectR)>0:
cr.execute(sumPreSelectSql,[info[2],info[0]]);
sumPreSelectSqlR = cr.fetchall();
print(monthPreSelectR);
print(sumPreSelectSqlR);
else:
print(“未查询到结果:”+info[0]+”,”+info[1]+","+info[2]);
except Exception as e:
print(e);
db.rollback();
except Exception as e:
print(e);
finally:
print(“完成”);
if cr != None:
cr.close();
if db !=None:
db.close();
python连接oracle
最新推荐文章于 2024-05-06 11:33:47 发布