title: cx_Oracle.DatabaseError: ORA-00904: "DATETIME"."DATETIME": invalid identifier
body: <p>I'm trying to export an Oracle DB with Python's cx_Oracle. I connect to DB, query all of the rows I need, and then build an INSERT statement with them.
  I'm using code similar to this:</p>
  
  <pre><code>table_name = "AUDIT"
  where_clause = "id &gt; 10"
  query = "SELECT * FROM " + table_name + " WHERE " + where_clause
  curs = db_conn.cursor()
  curs.execute(query)
  res = curs.fetchall()
  columns = []
  for i in range(0, len(curs.description)):
      columns.append(curs.description[i][0])
  column_names = ",".join(columns)
  statement = "INSERT INTO %s (%s) VALUES %s" % (table_name, column_names, row)
  print statement
  </code></pre>
  
  <p>The types are NUMBER,VARCHAR2,DATE,NUMBER, and I get an insert statement that looks good... except for the date field:</p>
  
  <pre><code>INSERT INTO AUDIT_LOG (LOG_DBID,USER_NAME,EVENT_DATE,SEVERITY) VALUES ('AUDIT_LOG_SQ.nextval', 'user@do',datetime.datetime(2018, 4, 28, 1, 57, 42), '1')
  </code></pre>
  
  <p>When I try to execute this, whether via sqlplus or the same cursor, I get the following error:</p>
  
  <pre><code>Error starting at line 1 in command:
  INSERT INTO AUDIT_LOG (LOG_DBID,USER_NAME,EVENT_DATE,SEVERITY) VALUES ('AUDIT_LOG_SQ.nextval', 'SYSTEM@do',datetime.datetime(2018, 4, 28, 1, 57, 42), '1')
  Error at Command Line:1 Column:95
  Error report:
  SQL Error: ORA-00904: "DATETIME"."DATETIME": invalid identifier
  00904. 00000 -  "%s: invalid identifier"
  </code></pre>
  
  <p>Without the datetime element the queries work just fine. 
  <strong>How do I insert a result I got from a cursor?</strong></p>
  
  <p>I checked SQL_Developer exports to compare with mine, and they have a different way of handling it:</p>
  
  <pre><code>INSERT INTO AUDIT_LOG (LOG_DBID,USER_NAME,EVENT_DATE,SEVERITY) VALUES ('AUDIT_LOG_SQ.nextval', 'user@do',to_timestamp('25-APR-18','DD-MON-RR HH.MI.SSXFF AM'), '1')
  </code></pre>
  
  <p>Which I haven't really found a way to duplicate (without turning the whole query into an ugly string concatenation), and I'm not sure I need to - there must be something I'm missing!</p>
  
  <p>Any help would be appreciated, thanks!</p>