Reputation: 781
Getting this : Cx_Oracle.DatabaseError: ORA-00984: column not allowed here ERROR while trying to insert data in Oracle Spatial DB via Python.
Reading data from XLS.Below is the code snippet of iterative reading and loading values :
for r in range (2,high_row ):
long = sheet_ranges['A'+str(r)].value
lat = sheet_ranges['B'+str(r)].value
state = sheet_ranges['C'+str(r)].value
cty = sheet_ranges['D'+str(r)].value
print lat
print long
print state
print cty
cur.execute('INSERT INTO NONMODEL_CAT_HAZARD (LONGITUDE,LATITUDE,STATE,COUNTRY) VALUES ('+str(long)+','+str(lat)+','+str(state)+','+str(cty)+')')
cxn.commit()
Output :
501 0 33.64 -117.84 CA US
Traceback (most recent call last): File "NMCatHazardLoadxls.py", line 32, in cur.execute('INSERT INTO NONMODEL_CAT_HAZARD (LONGITUDE,LATITUDE,STATE,COUNTRY) VALUES ('+str(long)+','+str(lat)+','+str(state)+','+str(cty)+')') cx_Oracle.DatabaseError: ORA-00984: column not allowed here
Please assist
Upvotes: 1
Views: 3605
Reputation: 961
You need to put all string values in single quotes (don't know which ones are strings, which numbers, so I did make all in single quotes):
cur.execute('INSERT INTO NONMODEL_CAT_HAZARD (LONGITUDE,LATITUDE,STATE,COUNTRY) VALUES (\''+str(long)+'\',\''+str(lat)+'\',\''+str(state)+'\',\''+str(cty)+'\')')
Upvotes: 3