Select to view content in your preferred language

cx_Oracle and python to move table data to numpy array

5719
2
Jump to solution
05-07-2015 07:53 AM
HåvardMoe
Deactivated User

Hi everyone

I've got a question regarding moving some table data from an Oracle DB to a numpy arrays. I've looked into the possibility of using cx_Oracle to access my Oracle DB and read data (tested, works) and now I'd like to make numpy arrays out of the data to work with the table data locally. The thing is, I don't know the table/field structure of the source data before I begin, so I can't really hardcode the numpy.dptyp() field types up front. Do anyone know if there is a way of getting this from the Oracle DB using cx_Oracle so I can build the numpy.dptyp() for each table?

Alternatively, of course, is there a better way of achieving this that I haven't thought of? (Let's assume I don't have access to arcpy and Oracle connections there...)

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Cursor.description will provide you the information you need, but you will have to create a mapping between cx_Oracle types and NumPy types.  It might also be worth checking out oracle_util.py on GitHub.

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor

Cursor.description will provide you the information you need, but you will have to create a mapping between cx_Oracle types and NumPy types.  It might also be worth checking out oracle_util.py on GitHub.

HåvardMoe
Deactivated User

Thank you.. The cursor.description seems to be what I'm looking for. The results from there should be parseable per table, and should be useable to create my numpy tables

I'll have a look at oracle_util.py as well. I've looked into it before and didn't quite like that it required a hack to cx_Oracle.

0 Kudos