python操作oracl数据库

 

#查询交易系统数据,判断当日是否有港股交易

import cx_Oracle
import os

conn = None
cursor = None

hkfile = 'hk.txt'
nohkfile = 'nohk.txt'
errfile = 'errhk.txt'

if os.path.exists(hkfile):
os.remove(hkfile)
if os.path.exists(errfile):
os.remove(errfile)


try:
conn = cx_Oracle.connect('trade/trade@10.1.1.92/tradetst')
#conn = cx_Oracle.connect('trade_r/pass#prod@192.168.2.211/trade')
cursor = conn.cursor ()
cursor.execute ("select a.L_BUSIN_AMOUNT from trade.TENTRUSTS a where a.C_MARKET_NO in ('n','o') and a.l_busin_amount <>0")
row = cursor.fetchall()
if row:
open(hkfile,'w')
else:
open(nohkfile, 'w')
except cx_Oracle.DatabaseError as msg:
open(errfile, 'w')

finally:
if cursor:
cursor.close()
if conn:
conn.close()

posted @ 2017-11-23 17:45  TIMLONG  阅读(166)  评论(0编辑  收藏  举报