安装cx_Oracle
wget http://download.oracle.com/otn/linux/instantclient/122010/instantclient-basic-linux.x64-12.2.0.1.0.zip
unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
cd instantclient_12_2/
cp * /usr/lib64 (/usr/lib)
pip install cx_oracle
创建py文件,注意名字不要和模块名、python关键字相同
#!/usr/bin/env python2
#-*- coding: utf-8 -*-
import cx_Oracle
connection = cx_Oracle.connect("peter", "peter", "172.16.1.13:1521/peter")
cursor = connection.cursor()
data = cursor.execute("select * from student")
row = data.fetchall() // 获取所有记录,格式为[(),(),()],一个元组一条记录
for x in row: // 迭代数组
for y in x:
print y,
print
one = data.fetchone() // 获取一条记录,格式为元组