使用cx_Oracle.makedsn连接oracle数据库时,如果用Service name不用SID,应该如下传参。

dns_tns=cx_Oracle.makedsn('host',port,service_name='service_name')

 

如果用SID不用Service name,应该如下传参。

dns_tns=cx_Oracle.makedsn('host',port,'sid_info')

dns_tns=cx_Oracle.makedsn('host',port,sid='sid_info')

 1 #!/usr/bin/env python3
 2 # -*- coding: utf-8 -*-
 3 
 4 import cx_Oracle  
 5 dns_tns=cx_Oracle.makedsn('host','port',service_name='service_name')  
 6 con = cx_Oracle.connect('user_name', 'password', dns_tns)  
 7 cur=con.cursor()  
 8 sql = "select * from tsp_cve_cvm_data" 
 9 cur.execute(sql)  
10 re = cur.fetchall()
11 for item in re:
12     print(item)
13 cur.close()
14 con.close()

参考cx_Oracle文档

posted on 2017-09-22 16:15  cyn_413  阅读(604)  评论(0编辑  收藏  举报