Skip to content

Instantly share code, notes, and snippets.

@jrrdev
Created October 6, 2017 01:26
Show Gist options
  • Save jrrdev/853f4d20036894031489d617e480af86 to your computer and use it in GitHub Desktop.
Save jrrdev/853f4d20036894031489d617e480af86 to your computer and use it in GitHub Desktop.
Python script to extract the content of a table from an Oracle Database to a flat file
#!/usr/bin/python
import json
import cx_Oracle
tables = ["table1", "table2"]
begin_sql = "SELECT * FROM "
end_sql = " WHERE COL_DATE > sysdate - 1"
con = cx_Oracle.connect('login/[email protected]/orcl')
for table in tables:
f = open(table + '.extract','w')
cur = con.cursor()
cur.arraysize = 2000
cur.execute(begin_sql + table + end_sql)
res = cur.fetchall()
f.write(res)
cur.close()
con.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment