I intend to insert data in a csv file row by row into oracle database using Python & Oracle connector, yet for text that are too long, I got an error
ORA-01704: string literal too long
The code is as follows:
from time import gmtime, strftime
with open(path-to-csv-file) as f:
reader=csv.DictReader(f,delimiter=',')
for row in reader:
today = strftime("%Y-%m-%d %H:%M:%S", gmtime())
if len(row['answer']) < 2000:
###[ The query in this part works]###
sqlquery="INSERT INTO TEST VALUES ('%s','%s')" %(row['answer'],today)
cur.execute(sqlquery)
else:
###[ The query below got and error ORA-01704: string literal too long]###
sqlquery="INSERT INTO TEST VALUES ('%s','%s')" %(row['answer'],today)
cur.execute(sqlquery)
I have searched on stackoverflow and tried to set the column name TEST1 to bigger size when the len(row["answer"]) is over 2000 with
cur.setinputsizes(TEST1 = cx_Oracle.CLOB)
Yet apparently it does not work since the query form is different.
When running in the else part:
else:
sqlquery="INSERT INTO TEST VALUES ('%s','%s')" %(row['answer'],today)
cur.setinputsizes(TEST1 = cx_Oracle.CLOB)
cur.execute(sqlquery)
ORA-01036: illegal variable name/number
was returned
Also, I have tried to declare the variable to varchar2 to solve this problem, but in vain. If anyone has a better idea with this issue, your help would be much much appreciated..