Today, I began to learn python, just learning Oracle, just to combine the cx_oracle learning.
Python relies on cx_oracle to interact with Oracle.
The first is to install these things, I use the environment is Centos6.4 64-bit version, found on the Internet cx_oracle is the highest support Python to 3.3,
So I'm under the Python3.3, using the database is 11g, so cx_oracle download the appropriate version.
Cx_oracle:http://sourceforge.net/projects/cx-oracle/files/5.1.2/
The above address is not the latest version, I use 5.1.3 at this address
cx_oracle:https://pypi.python.org/pypi/cx_oracle/5.1.3
First of all, my computer is loaded with that Python2.6, but I want to use python3.3, so download a python3.3 source package to install
Then I downloaded the cx_oracle RPM installation package, but after installation, using import Cx_oracle does not have this module.
Then I downloaded the cx_oracle source package, installed on their own, after installation, it can be used.
Cx_oracle source Package, there is a file is setup.py, which has a specific installation method,
Python setup.py Build Install
Here python I'm installing the 3.3, so I'm using
python3.3 setup.py Build Install
This is the installation process, and my machine is itself equipped with Oracle 11g.
2. Then it is used, I looked at the Internet, the use of posts are similar, the content is not much different, and then I found on the official website instructions
Address: http://cx-oracle.readthedocs.org/en/latest/module.html
You can use it according to the introduction here.
3. Put a test I just wrote, and I have a problem.
1.py#!/usr/local/bin/python3.3
Import Cx_oracle as Orcl
Print (Orcl.clientversion ()) Username = "Scott" passwd = "xx" host = "192.168.32.200" port = "1521" sid = "Oraclesid"
DSN = ORCL.MAKEDSN (host, port, sid) con = orcl.connect (username, passwd, DSN) cursor = con.cursor () sql = "Select ename, EMPN O from EMP "Cursor.execute (sql), result = Cursor.fetchall () print (" total: "+ str (cursor.rowcount))
For row in Result:print (row)
Cursor.close () Con.close ()
Print (ORCL. Date (2015,3,13))
Can see
Orcl. Date (2015,3,13) Here D is uppercase, I write when the case is not case-sensitive, written in lowercase, error.
Con.cursor () Here the first letter of the cursor is lowercase, I change to uppercase but error, I read the document Cx_oracle.cursor (connection)?
Here is the cursor, the first letter is uppercase, I was in doubt, how to format is not unified???
But then I found out I was wrong, using the cx_oracle call, the first letter is uppercase, that is, the kind of document,
But Con.cursor () is called with a connection, not the same thing.
Here Con.cursor () can also be changed, ORCL. Cursor (Con)
This also gets the cursor.
And that DSN is the shorthand for the data source name.
Python Learning Cx_oracle Learning record One