kirti haval
kirti haval

Reputation: 11

CX ORACLE - Python :: Update Statement not working

I am facing starange issue I am not able to update the ORACLE DB Table from Python using UPDATE statement. The DB connection is good and I can fetch the records.

Whenever I am updating the characters / alphanumeric string values I am getting following error.

Continuously I am getting error :: cx_Oracle.DatabaseError: ORA-00904: : invalid identifier

Surprisingly, for the Numeric Field value updates it's not an issue.

Python Version - 3.7 CX_Oracle - 7.1 Windows 10 (Personal Machine) Oracle 11.2 R2

#python Code

import cx_Oracle

conn = cx_Oracle.connect('SYSTEM/Aditya201$@//localhost:1521/JTORCL')
c = conn.cursor()

# Update Rows
#statement = 'UPDATE TEST_JT SET EMP_NAME = "JSXX YA" WHERE EMP_ID = 1'
c.execute(statement)

conn.commit()
c.close()
conn.close()

Update Statement not working with non numeric update values as shown above

Upvotes: 1

Views: 2660

Answers (1)

Anthony Tuininga
Anthony Tuininga

Reputation: 7096

In order to improve performance and eliminate concerns about quoting and SQL injection, it is far better to use bind variables. So your code should look something like this:

statement = 'UPDATE TEST_JT SET EMP_NAME = :1 WHERE EMP_ID = :2'
c.execute(statement, ["JSXX YA", 1])

Upvotes: 1

Related Questions