cx_Oracle 脚本例子

根据总部提供的imsi,xim号,查询是否已成功办理业务。
做下笔记

#!/usr/bin/env python
# encoding: utf-8
"""
总部白卡对账确认.py

Created by rikugun on 2010-08-05.
Copyright (c) 2010 TYDIC. All rights reserved.
"""

import sys
import os
import cx_Oracle


DATA_FILE = 'data.dat'
RESULT_FILE = 'output.cvs'
OFF_SET_PROC_ID = 1
OFF_SET_IMSI = 2
OFF_SET_XIM = 7

def main():
	conn = cx_Oracle.Connection('log','pwd','crmapp')
	cur = conn.cursor()
	cur.prepare(''' select 1 from busi.info_gsm where xim_number = :xim and imsi = :imsi ''')
	f = open(RESULT_FILE,'w')
	for	line in open(DATA_FILE,'r'):
		fields = line.split()
		cur.execute(None,{'xim':fields[OFF_SET_XIM],'imsi':fields[OFF_SET_IMSI]})
		ret = cur.fetchall()
		# print ret
		f.write(fields[OFF_SET_PROC_ID]+'\t'+ ('success' if len(ret)>0 else 'failed') +'\n')
	f.close()
	cur.close()
	conn.close()

if __name__ == '__main__':
	main()

你可能感兴趣的:(oracle,python,OS,脚本,cvs)