Learn python, recording the process to make a backup, convenient for later inquiries. Learn from other great God articles that will be recorded before the text.
Reference article: http://evil850209.iteye.com/blog/1394932
Http://www.cnblogs.com/oubo/archive/2012/07/24/2607034.html
Steps:
1, download Python and Oracle.
2, go to python website Download cx_oracle package, run. You should also be able to run it with code. Download Address http://cx-oracle.sourceforge.net/,
3, add Tnsnames.ora file.
This file is actually configured when you use Oracle, which is equivalent to setting the access address of the database.
Datacent=
(DESCRIPTION = (
address_list =
(address = (PROTOCOL = TCP) (HOST = IP) (PORT = 1521))
( Connect_data =
(service_name = datacent)
)
)
4. Configure Environment variables
5, the package has been installed, in Python under test to run Cx_oracle package, and linked to the database.
#-*-Coding:utf-8-*-
import cx_oracle
conn=cx_oracle.connect (' username/password @ database IP address: 1521/datacent ')
cur= Conn.cursor () #游标
printheader = true# First row
cur.execute ("Select Cust_no,reg_date from Cust_info")
#data = Cur.fetchall () #所有记录
data=cur.fetchone () #一条记录
for row in data:
print "%s,%d" (Row[0], row[1]) #转化格式 C10/>cur.close () #关闭游标
conn.close () #关闭数据链接
The above code can be run to link the database, then do data processing or other analysis.
Cons: The difference between Python and R is that from the database after the number can not be built like r a table, not too convenient, there may be a solution I do not know, know the classmate can tell me, let me a data learning python this biased computer tools, cough cough or a lot of places do not understand.