Insert into oracle table from CSV using python
<p>I am reading a csv file with 5 columns and push to oracle table</p>

<p><a href="http://i.stack.imgur.com/kkoNu.jpg" rel="nofollow">CSV file Structure</a></p>

<p>I know there are lots of resources on this .. But even then I am unable to find a solution for my problem </p>

<p>Code to read the CSV to python : </p>

<pre><code> import csv
 reader = csv.reader(open("sample.csv","r"))
 lines=[]
 for line in reader:
      lines.append(line)
  print lines 
</code></pre>

<p>Output :</p>

<blockquote>
  <p>[['Firstname', 'LastName', 'email', 'Course_name', 'status'],
  ['Kristina', 'Bohn', 'abc@123.com', 'Guide to
  Capnography in the Management of the Critically Ill Patient (CE)',
  'Registered'], ['Peggy', 'Lutz', 'gef@123.com',
  'Guide to Monitoring EtCO2 During Opioid Delivery (CE)', 'In
  Progress']]</p>
</blockquote>

<p>Code to push the list to Oracle table :</p>

<pre><code>import cx_Oracle
con = cx_Oracle.connect('username/password@tamans*****vd/Servicename')
ver=con.version.split(".")
print(ver)
cur=con.cursor()
cur.execute("INSERT INTO TEST_CSODUPLOAD ('FIRSTNAME','LASTNAME','EMAIL','COURSE_NAME','STATUS') VALUES(:1,:2,:3,:4,:5)",lines)
con.commit ()
cur.close()
</code></pre>

<p>I am getting the error :</p>

<p><strong>DatabaseError: ORA-01484: arrays can only be bound to PL/SQL statements</strong></p>

<p>Please help me solve the issue Thanks in advance </p>

<p>The problem is that you are trying to pass an array to a single insert statement. You have two options here:</p>

<p>1) Use a loop to insert each row separately:</p>

<pre><code>for line in lines:
    cursor.execute("insert into ...", line)
</code></pre>

<p>2) Use cursor.executemany() instead to do an array insert</p>

<pre><code>cursor.executemany("insert into ...", lines)
</code></pre>

<p>The second option is more efficient but you have to make sure that the type of data is consistent for each line. If you have a number in one row and a string in the next row an error will be raised.</p>

python oracle csv insert-into cx-oracle