Python Connect Oracle Configuration

Source: Internet
Author: User
Tags dsn


Environment:

Operating System: win7 ,CPU is inter pc

Oracle server:oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production

Oracle Local client:Release 11.2.0.1.0 32bit Production

Python version:python2.7.5 (Installation path:C:\Python27\)

Cx_oracle version:cx_oracle-5.2.1-11g.win-amd64-py2.7.exe

Iinstantclient version:instantclient-basic-win-x86-64-11.2.0.1.0.zip

In the course of learning python, you need to connect to the Oracle database, so install cx_oracle.

install cx_ Oracle-5.2.1-11g.win-amd64-py2.7.exe error. Hint: import cx_oracle

Importerror:dll load failed:%1 is not a valid Win32 application. According to the error message should be missing dll file, because my native Oracle Client is a three-bit, bit of cx_oracle Program calls + bit of the dynamic library will definitely error.

according to the article http://blog.csdn.net/huzhenwei/article/details/3946308 pointing, to the Oracle website to download the instance client, the address is :

Http://www.oracle.com/technology/software/tech/oci/instantclient/index.html.

I downloaded the Instantclient-basic-win-x86-64-11.2.0.1.0.zip this version.

Direct Decompression the C:\instantclient_11_2 directory.

in the environment variables , in the system variables , add:

oracle_home = C:\instantclient_11_2 (online says need, but test does not add also can)

tns_admin = C:\instantclient_11_2    (online says need, but test does not add)

modify path variable, added later c:\instantclient_11 _2

and then unpack the package. oci.dll file under%python_home%\lib\site-packages, again Import no more error.

execute test python pin this newspaper wrong, hint cx_oracle Interface error:unable to acquire Oracle enviroment handle. Start Plsql login is just the TNS, but landed on the error ORA-1 thought to be instance client and previously installed 32-bit Oracle client conflict, ORA-12557. The feeling is that this 64-bit instance client is in conflict with the 32-bit Oracle client that was previously installed. So the environment variables in the Oracle_path deleted, you can land plsql. But the test statement still reported the mistake. Toss a half-day, the last dead horse when live horse medicine, try to C:\instantclient_11_2 inside the DLL files are copied to the Python C:\Python27\Lib\site-packages directory, and run a bit, incredibly not error. Then delete one by one, and finally found that Oraociei11.dll deleted will be error, and other DLLs deleted re-run will not error.

but using Plsql landing or will error, had to the environment variable oracle_home deleted, does not affect the use of cx_oracle. The principle is not very clear, first recorded.

P Ython test script:

#!/usr/bin/python#coding=utf-8import cx_oracleusername = "SMB" passwd = "CZTY_SMB" host = "192.168.150.233" port = "1521"  Sid = "Zsms" DSN = CX_ORACLE.MAKEDSN (host, port, sid) con = cx_oracle.connect (username, passwd, DSN) cursor= con.cursor () SQL = ' SELECT Smbms, Prtms from T_user_mobile_dz ' cursor.execute (sql) result = Cursor.fetchall () print "total:" + str (CURSOR.R Owcount) for row in Result:print rowcursor.close () con.close ()


Python Connect Oracle Configuration

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.