最近使用Python连接Oracle数据库遇到了一些连接问题,发现有以下两种主要的连接方式:
method1
import cx_Oracle
con = cx_Oracle.connect( DataBase Urser Name, password,IP)
cursor = con.cursor()
SQL_Select='select * from tableName where condition1 and condition2 order by Attr1 desc'
#读取TableName表中满足Condition1 和 Condition2 所有字段数据,并按照Attr1字段降序排列。若升序排列则用order by Attr1 asc
cur.execute(SQL_Select)
cursor.close()
con.close()
method2
import cx_Oracle
dsn = cx_Oracle.makedsn(IP, '1521', SID)
conn = cx_Oracle.connect(DataBase Urser Name, password, dsn)
cur = conn.cursor()
SQL_Select='select * from tableName where condition1 and condition2 order by Attr1 desc'
#读取TableName表中满足Condition1 和 Condition2 所有字段数据,并按照Attr1字段降序排列。若升序排列则用order by Attr1 asc
cur.execute(SQL_Select)
cursor.close()
con.close()