Skip to content

Instantly share code, notes, and snippets.

@t0mst0ne
Created October 23, 2015 14:53
Show Gist options
  • Save t0mst0ne/825f0511bc5e20925481 to your computer and use it in GitHub Desktop.
Save t0mst0ne/825f0511bc5e20925481 to your computer and use it in GitHub Desktop.
Using python with cx_Oracle to query Oracle and transform to pandas dataframe
#!/usr/bin/env python
#coding:UTF-8
# Be sure to install the correct version of Oracle library
# https://gist.github.com/kimus/10012910
import pandas as pd
import pandas.io.sql as psql
import cx_Oracle
import os
os.environ["NLS_LANG"] = "AMERICAN_AMERICA.AL32UTF8"
dsn_tns = cx_Oracle.makedsn('IP', 1521, 'name')
ora_conn = cx_Oracle.connect('user/pass',dsn=dsn_tns)
df1 = psql.read_sql('SELECT * FROM table', con=ora_conn)
ora_conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment