Cx Oracle Python

Environmental Science :

win7 32 Bit system

Python3.6 (32bit)

Install the module :

  1. CxOracle version 8.3 (Development) cxOracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions.
  2. CxOracle is a module that enables access to Oracle Database and conforms to the Python database API specification. This module is currently tested against Oracle Client 21c, 19c, 18c, 12c, and 11.2, and Python 3.6, 3.7, 3.8 and 3.9. Older versions of cxOracle may be used with previous Python releases.
Cx_oracle

Summary: in this tutorial, you will learn how to select data from Oracle Database using fetchone, fetchmany, and fetchall methods. To select data from the Oracle Database in a Python program, you follow these steps: First, establish a connection to the Oracle Database using the cxOracle.connect method.

cx_Oracle Module Download ( Download address :https://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_oracle)

If you download it on the website , Remember to download and download python The version corresponds to . Because I was in 64 Bit system installation , It has always been used cx_Oracle-5.3+oci12c-cp36-cp36m-win_amd64.whl This file , So this time I downloaded the corresponding 32 Bit system cx_Oracle‑5.3+oci12c‑cp36‑cp36m‑win32.whl.

Use pip install path install ,path Is the path to the file

Ciaoradio h101 software update. Oracle client instantclient_12_1( Download address :http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html)

Cx Oracle Python

because cx_Oracle The file download is cx_Oracle‑5.3+oci12c‑cp36‑cp36m‑win32.whl, The corresponding is 32 Bit and version is 12 Of

Will download instantclient-basic-nt-12.1.0.2.0 In the document oci.dll oraociei12.dll and oraocci12.dll Copy three files to python The installation path ( Like myself D:softPython36Libsite-packages) Next .

Cx Oracle Python

problem

stay IDLE Run in

Report errors :ImportError: DLL load failed: The specified module was not found

The general reason for this problem is : No, copy Previously mentioned oci.dll Documents or Oracle Client version and cx_Oracle Version inconsistency

And I have copy 了 oci.dll file . And judging from the file name, the two versions are consistent

I tested all of them 12 Version of Oracle client , Include 64 position , None of them succeeded .( test 64 I'm going to give you an error :ImportError: DLL load failed: %1 It's not effective Win32 Applications , It means the operating system 、cx_Oracle and instantclient The number of digits is different , I couldn't think of any other way at that time , All kinds of attempts )

I realized later that maybe cx_Oracle The problem of ..

terms of settlement

stay cmd Run in

to update cx_Oracle Module to the latest version , Problem solving .

Need to connect Python to an Oracle database using cx_Oracle connect?

If so, in this short guide, you’ll see the steps to establish this type of connection from scratch.

Steps to Connect Python to Oracle using cx_Oracle connect

Python

Step 1: Install the cx_Oracle package

If you haven’t already done so, install the cx_Oracle package. You may use the following syntax to install the cx_Oracle package under Windows:

Step 2: Retrieve the connection information

Next, retrieve the connection information. Wcf binaryencoded message inspector for fiddler for mac. You can do that by locating your tnsnames.ora file on your computer (e.g., type tnsnames.ora in the Windows search bar).

Now, open your tnsnames.ora file and look for your desired connection.

It should look like the info below (highlighted in colors 3 elements that you usually need to look for before you can establish a connection between Python and your Oracle database):

SYSTEM_OCON =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Host Name)(PORT = Port Number))
(LOAD_BALANCE = YES)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = Service Name)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)

Step 3: Connect Python to Oracle using cx_Oracle connect

Cx Oracle Python

Finally, copy/type the following syntax in Python while adding the needed info based on your Oracle connection:

Please note that there are additional ways to retrieve the information needed to facilitate your connection to the Oracle database.

For example, you can run the following query to get the Service Name:

Cx_oracle Python Examples

You may also run the following query to get the list of users:

Conclusion and Additional Resources

You just saw how to connect Python to Oracle using cx_Oracle connect. Once you established such a connection, you can start using SQL in Pythonto manage your data.

You can learn more about the different types of connections between Python and other database applications by visiting these guides:

Install Cx_oracle Python

For further information about the cx_Oracle package, please refer to the cx_Oracle’s documentation.