Skip to content Skip to sidebar Skip to footer

How To Export Parsed Data From Python To An Oracle Table In Sql Developer?

I have used Python to parse a txt file for specific information (dates, $ amounts, lbs, etc) and now I want to export that data to an Oracle table that I made in SQL Developer. I h

Solution 1:

From Import a CSV file into Oracle using CX_Oracle & Python 2.7 you can see overall plan. So if you already parsed data into csv you can easily do it like:

import cx_Oracle
import csv

dsnStr = cx_Oracle.makedsn("sole.wh.whoi.edu", "1526", "sole")

con = cx_Oracle.connect(user="myusername", password="mypassword",     dsn=dsnStr)
print (con.version)

#imp 'Book1.csv' [this didn't work]

cursor = con.cursor()
print (cursor)

text_sql = '''
INSERT INTO tablename (firstfield, secondfield) VALUES(:1,:2)
'''

my_file = 'C:\CSVData\Book1.csv'
cr = csv.reader(open(my_file,"rb"))
for row in cr:    
    print row
    cursor.execute(text_sql, row)
    print 'Imported'
con.close()

Post a Comment for "How To Export Parsed Data From Python To An Oracle Table In Sql Developer?"