我在使用cx_oracle运行executemany时遇到问题
WHen如果我运行以下语句,将收到ORA-01036: illeagal variablename/number
infotext_list是应该与"SOMETHING"进行比较的字符串列表。它看起来像"abc","bcd","def",...并且其中的每个字符串都应该与另一个数据库表中的内容进行比较!
insert_stmt = 'INSERT INTO data_table (...) SELECT ... FROM other_table WHERE SOMETHING = ? '
curs.executemany(insert_stmt, infotext_list)如果我遍历infotext_list并使用标准的execute()方法,它可以很好地工作,但它永远需要花费时间。
发布于 2015-12-11 15:43:47
为了让它为我工作,我做了几件事。
1-将infotext_list更改为mappings or sequences列表
infotext_list = [("abc",), ("bcd",), ("def",)] --notice the extra , inside the ()或
infotext_list = [{'value':"abc"}, {'value':"bcd"}, {'value':"def"}]2-改变?to be :如果要使用映射,则为value;如果要使用序列,则为:1 (或任何其他:name
这两种方法都适用于我
infotext_list = [("abc",), ("bcd",), ("def",)]
insert_stmt = 'INSERT INTO data_table (...) SELECT ... FROM other_table WHERE SOMETHING = :1 '
curs.executemany(insert_stmt, infotext_list)
infotext_list = [{'value':"abc"}, {'value':"bcd"}, {'value':"def"}]
insert_stmt = 'INSERT INTO data_table (...) SELECT ... FROM other_table WHERE SOMETHING = :value '
curs.executemany(insert_stmt, infotext_list)我有一篇关于在crud操作here中使用cx_Oracle的简短文章。
https://stackoverflow.com/questions/27942183
复制相似问题