Python Load csv file to Oracle table
<p>I'm a python beginner. I'm trying to insert records into a Oracle table from a csv file. 
csv file format : Artist_name, Artist_type, Country . I'm getting below error:</p>

<pre><code>Error: File "artist_dim.py", line 42, in &lt;module&gt;
    cur.execute(sqlquery)
cx_Oracle.DatabaseError: ORA-00917: missing comma


    import cx_Oracle as cx
    import csv
    import sys

    ##### Step 1 : Connect to Oracle Database#########
    conn_str=u'hr/hr@localhost:1521/PDBORCL'
    conn= cx.connect(conn_str)
    cur=conn.cursor()
    #######################################
    #### Step 2: FETCH LATEST ROW ID FROM ARTIST_DIM###
    query="SELECT nvl(max(row_id)+1,1) from artist_dim"
    cur.execute(query)
    rownum=cur.fetchone()
    x=rownum[0] 

    with open('D:\python\Artist.csv') as f:
        reader=csv.DictReader(f,delimiter=',')
        for row in reader:
            sqlquery="INSERT INTO ARTIST_DIM VALUES (%d,%s,%s,%s)" %(x,row['Artist_name'],row['Artist_type'],row['Country'])
                    cur.execute(sqlquery)
            x=x+1

    conn.commit()
</code></pre>

<p>When I try to read the file it is working correctly.</p>

<pre><code>    ##### Just to Read CSV File############################
    with open('D:\python\Artist.csv') as f:
        reader = csv.DictReader(f, delimiter=',')
        for row in reader:
            a="row_id %d Artist : %s type : %s  Country : %s " %(x,row['Artist_name'],row['Artist_type'],row['Country'])
            print(a)
            x=x+1
    print(row['Artist_name'],",",row['Artist_type'],",",row['Country'])  

Also, when I try to insert using hard coded values it is working

    sqlquery1="INSERT INTO ARTIST_DIM VALUES (%d,'Bob','Bob','Bob')" %x
    cur.execute(sqlquery1)
</code></pre>

<p>Put quotes around the values:</p>

<pre><code>sqlquery="INSERT INTO ARTIST_DIM VALUES (%d,'%s','%s','%s')" %(x,row['Artist_name'],row['Artist_type'],row['Country'])
</code></pre>

<p>Without the quotes it translates to:</p>

<pre><code>sqlquery="INSERT INTO ARTIST_DIM VALUES (1, Bob, Bob, Bob)"
</code></pre>

python oracle python-3.x