Cx_Oracle: error 933. ORA-00933: "SQL command not executed as expected": SQL command error?
Similar questions have been asked before, but I still haven't been able to figure out a solution for this. My code:
try:
connection = cx_Oracle.connect(ORACLE_CONNECT)
logger.info("Connection to Oracle success.")
print ("Oracle DB version: " + connection.version)
print ("Oracle client encoding: " + connection.encoding)
print ("Python version: " + platform.python_version())
except cx_Oracle.DatabaseError as e:
error, = e.args
if error.code == 1017:
print ("Username/password invalid.")
logger.debug("Username/password invalid: %s", error.code)
else:
logger.debug("Database connection error: %s", e)
print ("Database connection error: %s".format(e))
raise
cursor = connection.cursor()
smsreport_text_new = tuple(smsreport_text)
find_command = self.identify_unique_msgid(smsreport_list)
cursor.execute(find_command)
def identify_unique_msgid(self, smsreport_list):
msgid_i_to_be_crosschecked = smsreport_list.get('msgid_i')
msgid_ii_to_be_crosschecked = smsreport_list.get('msgid_ii')
find_command = 'SELECT * FROM myTable WHERE msgid_i = {0}'.format(msgid_i_to_be_crosschecked)
print (find_command)
return find_command
find_command
as follows:
SELECT * FROM myTable WHERE msgid_i = 2R67C865FB6ZHG5A9
I tried with and without comma at the end of the SQL query but still doesn't work. I know the connection is working because I have another query (see below) and this is writing data to a table. It's just that when trying to find rows containing certain values, I get this error message.
insert into xura_push (date_sms, result_sms, msgid, msgparts, msgid_i, msgid_ii) values (TO_DATE(:1, 'dd-mon-yyyy hh24:mi:ss'), :2, :3, :4, :5, :6)
Where am I going wrong?
Cheers, pymat.
+3
source to share
1 answer
As stated in the above notes, use the parameters like this:
def identify_unique_msgid(self, smsreport_list):
msgid_i_to_be_crosschecked = smsreport_list.get('msgid_i')
msgid_ii_to_be_crosschecked = smsreport_list.get('msgid_ii')
find_command = 'SELECT * FROM myTable WHERE msgid_i = :msgid'
return find_command, dict(msgid = msgid_i_to_be_crosschecked)
cursor = connection.cursor()
smsreport_text_new = tuple(smsreport_text)
find_command, args = self.identify_unique_msgid(smsreport_list)
cursor.execute(find_command, args)
+1
source to share