<p>Given an Oracle table created using the following:</p>

<pre><code>CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME ZONE);
</code></pre>

<p>Using the Python ODBC module from its <a href="http://www.python.org/download/windows/" rel="nofollow noreferrer">Win32 extensions</a> (from the win32all package), I tried the following:</p>

<pre><code>import dbi, odbc

connection = odbc.odbc("Driver=Oracle in OraHome92;Dbq=SERVER;Uid=USER;Pwd=PASSWD")

cursor = connection.cursor()
cursor.execute("SELECT WhenAdded FROM Log")

results = cursor.fetchall()
</code></pre>

<p>When I run this, I get the following:</p>

<pre><code>Traceback (most recent call last):
...
    results = cursor.fetchall()
dbi.operation-error: [Oracle][ODBC][Ora]ORA-00932: inconsistent datatypes: expected %s got %s 
in FETCH
</code></pre>

<p>The other data types I've tried (VARCHAR2, BLOB) do not cause this problem. Is there a way of retrieving timestamps?</p>

[{'answer_id': 38442, 'author': 'Jason Etheridge', 'author_id': 2193, 'author_profile': 'https://Stackoverflow.com/users/2193', 'pm_score': 1, 'selected': False, 'text': '<p>My solution to this, that I hope can be bettered, is to use Oracle to explicitly convert the TIMESTAMP into a string:</p>\n\n<pre><code>cursor.execute("SELECT TO_CHAR(WhenAdded, \'YYYY-MM-DD HH:MI:SSAM\') FROM Log")\n</code></pre>\n\n<p>This works, but isn\'t portable. I\'d like to use the same Python script against a SQL Server database, so an Oracle-specific solution (such as TO_CHAR) won\'t work.</p>\n'}, {'answer_id': 38718, 'author': 'David Sykes', 'author_id': 3154, 'author_profile': 'https://Stackoverflow.com/users/3154', 'pm_score': 3, 'selected': True, 'text': "<p>I believe this is a bug in the Oracle ODBC driver. Basically, the Oracle ODBC driver does not support the <code>TIMESTAMP WITH (LOCAL) TIME ZONE</code> data types, only the <code>TIMESTAMP</code> data type. As you have discovered, one workaround is in fact to use the <code>TO_CHAR</code> method.</p>\n\n<p>In your example you are not actually reading the time zone information. If you have control of the table you could convert it to a straight <code>TIMESTAMP</code> column. If you don't have control over the table, another solution may be to create a view that converts from <code>TIMESTAMP WITH TIME ZONE</code> to <code>TIMESTAMP</code> via a string - sorry, I don't know if there is a way to convert directly from <code>TIMESTAMP WITH TIME ZONE</code> to <code>TIMESTAMP</code>.</p>\n"}]
['https://Stackoverflow.com/questions/38435', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2193/']