Read and write by Python

Python seems to be a very convenient way to transfer data to and fro Oracle. It has capabilities to set up a connection and it seems quite capable to transfer a matrix into a table and vice versa. Next code shows this. It first retrieves the content of a table. In a second step some data from a matrix are stored into a table.

import cx_Oracle
con = cx_Oracle.connect('scott/bunvogni@van-maanen.com/orcl')
cur = con.cursor()
cur.execute('select * from departments order by department_id')
res = cur.fetchall()
print res
rows = [ (1, "First" ),
         (2, "Second" ),
         (3, "Third" ),
         (4, "Fourth" ),
         (5, "Fifth" ),
         (6, "Sixth" ),
         (7, "Seventh" ) ]
cur = con.cursor()
cur.setinputsizes(int, 20)
cur.executemany("insert into mytable(id, data) values (:1, :2)", rows)
con.commit()
con.close()

Door tom