Python版本:3.7
Oracle版本:12c
注释:Oracle12c采取的是RAC负载,对外的SID和service不相同
采用的模块:cx_Oracle
查询语句的操作
在这里插入代码片import cx_OracleTNS = \'username/password@ip:port/service\'connection = cx_Oracle.connect(TNS)cursor = connection.cursor()sql = \'\'\'select * from test\'\'\'cursor.execute(sql)#print(type(cursor)) <class \'cx_Oracle.Cursor\'>#print(type(cursor.description)) <class \'list\'>#读取结果集的字段值sql_title = [i[0] for i in cursor.description]for a in sql_title:a = a#print(a,type(a))#读取结果集的明细值sql_detail = []for i in cursor:sql_detail.append(i) #将SQL的结果集的数据导入list中#print(type(i)) #<class \'tuple\'> 每个tuple代表结果的的一行数据print(sql_detail[0]) #输出结果集合的第一个条数据#输出指导条数的每个字段数据for b in sql_detail[0]:print(b)#connection.commit()cursor.close()connection.close()