import cx_Oracle as orcl
from conf import config
def query(sql, username, passwd, host, port, sid):
”’
:param username: 用户名
:param passwd: 密码
:param host: 地址
:param port: 端口
:param sid: 数据库名
:param sql: 查询语句
:return:
”’
dsn = orcl.makedsn(host, port, sid)
conn = orcl.connect(username, passwd, dsn)
cursor = conn.cursor()
cursor.execute(sql)
desc = [d[0] for d in cursor.description]
result = [dict(zip(desc,line)) for line in cursor]
cursor.close()
conn.close()
return result
if name == ‘main‘:
sql = “select * from tt_ident_data where waybill_no=’613456783306’”
result = query(sql, **config.database_ars)
print result