Created
October 6, 2017 01:26
-
-
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
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
#!/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