Python Learning Cx_oracle Learning record One

Source: Internet
Author: User
Tags dsn

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.

    1. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.