Python connecting to oracle database

disclaimer cx_oracle 5.2 only support up to python 3.4

cx_Oracle
cx_Oracle-5.3-11g.win-amd64-py3.4.exe:
https://pypi.python.org/packages/af/ad/3ee2a0ba579d400a9fd018d21462b8ba69903d9154da7154450614f108e0/cx_Oracle-5.3-11g.win-amd64-py3.4.exe#md5=1b04f0eec6f6d1dc62ee4d94ca917335

Instant Client
Download and install following, and extract to below  folder
C:\Python\instantclient_11_2

Version 11.2.0.4.0 
Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
Download instantclient-basic-windows.x64-11.2.0.4.0.zip (54,956,947 bytes)


Instant Client Package - SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client
Download instantclient-sqlplus-windows.x64-11.2.0.4.0.zip (821,172 bytes)

Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
Download instantclient-sdk-windows.x64-11.2.0.4.0.zip (1,446,625 bytes)

Instant Client Package - ODBC: Additional libraries for enabling ODBC applications
Download instantclient-odbc-windows.x64-11.2.0.4.0.zip (1,358,385 bytes)
Windows environment variables:

LD_LIBRARY_PATH : C:\Python\instantclient_11_2 
ORACLE_HOME : C:\Python\instantclient_11_2 
PATH : C:\Python\instantclient_11_2 
PATH : C:\Program Files\Python36\ 
PATH : C:\Program Files\Python36\Scripts\ 
TNS_ADMIN : C:\Python\instantclient_11_2

python code:
#http://cx-oracle.sourceforge.net/
import cx_Oracle
import os

ip = 'localhost'
port = 1521
SID = 'WRITE SID'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
username = 'USERNAME'
password= 'PASSWORD'

#db = cx_Oracle.connect(username, password, dsn_tns)
#This can also be done maually
# You can set these in system variables but just in case you didnt
os.putenv('ORACLE_HOME', 'C:\Python\instantclient_11_2')
#os.putenv('LD_LIBRARY_PATH', 'C:\Python\instantclient_11_2')

connection = cx_Oracle.connect(username, password, dsn_tns)
cursor = connection.cursor()
querystring = """select * from INTEGRATION_FILE where
FILENAME = 'CREMUL_136_JE'"""
cursor.execute(querystring)

for row in cursor.fetchall():
    print (row)


///

Install Anaconda: https://www.continuum.io/downloads (used for getting packages)
It will also install spyder which serves as a client for writing code

use can use anaconda to control the python version
run the anaconda code through Anaconda promt.exe that comes with the installation.
use anaconda cloud to search for modules/packages and get the code you need to paste into anaconda prompt

Kommentarer

Populære opslag fra denne blog

Xpath cheat sheet

Reading Email

pip whl install python