Wednesday, November 27, 2019

Connecting Oracle with Python via cx_Oracle extension


Installation Prerequisites

  • Python 2.7, 3.5 or above
  • Oracle Client / Oracle Instant Client "Basic" or "Basic Light"
  • libaio / libaio1 package


Installation Reference



Sample Python Code

import cx_Oracle

# Make DSN address. Real values for host address, port and service name were replaced by '<>'.

dsn = cx_Oracle.makedsn('<host_address>', '<port>', service_name='<service_name>')

# Connect to DSN

orcl = cx_Oracle.connect(user='<username>', password='<password>', dsn=dsn)

# Get cursor

cursor = orcl.cursor()

# Execute SQL statement

cursor.execute('<SQL SELECT STATEMENT>')

# Fetch result

data = cursor.fetchone()

No comments:

Post a Comment

CSP on Apache

To add CSP to root if sort of funny. The following will NOT work for most cases !!     <LocationMatch "^/$">        Header s...