-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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