之前已经提出了类似的问题,但我仍然无法找到解决方案.我的代码:

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看起来像这样:

SELECT * FROM myTable WHERE msgid_i = 2R67C865FB6ZHG5A9

我在SQL查询结束时尝试使用和不使用分号,但仍然失败.我知道连接有效,因为我有另一个查询(见下文),这会将数据写入表中.只是在尝试查找包含某些值的行时,我收到此错误消息.

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)

我哪里错了?

干杯,pymat.

解决方法:

如上面的评论中所述,使用以下参数:

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)

标签:python,sql,python-3-x,oracle,cx-oracle

来源: https://codeday.me/bug/20190627/1307408.html

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐