Skip to content

Instantly share code, notes, and snippets.

@tpjfern03
Forked from mvaz/cx_oracle_to_pandas.py
Created November 29, 2018 18:33
Show Gist options
  • Select an option

  • Save tpjfern03/26431c958d17732a5197d6846771c069 to your computer and use it in GitHub Desktop.

Select an option

Save tpjfern03/26431c958d17732a5197d6846771c069 to your computer and use it in GitHub Desktop.
Example of executing and reading a query into a pandas dataframe #cx_oracle
import cx_Oracle
import pandas
connection = cx_Oracle.connect('username/pwd@host:port/dbname')
def read_query(connection, query):
cursor = connection.cursor()
try:
cursor.execute( query )
names = [ x[0] for x in cursor.description]
rows = cursor.fetchall()
return pandas.DataFrame( rows, columns=names)
finally:
if cursor is not None:
cursor.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment