title: Python Cx_Oracle; How Can I Execute a SQL Insert using a list as a parameter
body: <p>I generate a list of ID numbers. I want to execute an insert statement that grabs all records from one table where the ID value is in my list and insert those records into another table. </p>
  
  <p>Instead of running through multiple execute statements (as I know is possible), I found this cx_Oracle function, that supposedly can execute everything with a single statement and list parameter. (It also avoids the clunky formatting of the SQL statement before passing in the parameters) But I think I need to alter my list before passing it in as a parameter. Just not sure how.</p>
  
  <p>I referenced this web page:
  <a href="https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-executemany.html" rel="nofollow noreferrer">https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-executemany.html</a></p>
  
  <pre><code>ids = getIDs()
  print(ids)
  </code></pre>
  
  <blockquote>
    <p>[('12345',),('24567',),('78945',),('65423',)]</p>
  </blockquote>
  
  <pre><code>sql = """insert into scheme.newtable
       select id, data1, data2, data3
       from scheme.oldtable
        where id in (%s)"""
  cursor.prepare(sql)
  cursor.executemany(None, ids)
  </code></pre>
  
  <p>I expected the SQL statement to execute as follows:</p>
  
  <blockquote>
    <p>Insert into scheme.newtable 
    select id, data1, data2, data3 from scheme.oldtable where id in ('12345','24567','78945','65423')</p>
  </blockquote>
  
  <p>Instead I get the following error:
  ORA-01036: illegal variable name/number</p>
  
  <p>Edit:
  I found this StackOverflow: <a href="https://stackoverflow.com/questions/14904033/how-can-i-do-a-batch-insert-into-an-oracle-database-using-python">How can I do a batch insert into an Oracle database using Python?</a> 
  I updated my code to prepare the statement before hand and updated the list items to tuples and I'm still getting the same error.</p>