使用cx_oracle
运行executemany
时遇到问题
当我运行以下声明时,我收到ORA-01036: illeagal variablename/number
infotext_list
是应与"SOMETHING"
进行比较的字符串列表
看起来像[“abc”,“bcd”,“def”,...],其中的每个字符串都应与其他数据表中的SOMETHING进行比较!
insert_stmt = 'INSERT INTO data_table (...) SELECT ... FROM other_table WHERE SOMETHING = ? '
curs.executemany(insert_stmt, infotext_list)
如果我遍历infotext_list
并使用标准的execute()
方法,它就可以正常工作,但需要永远。
答案 0 :(得分:0)
我改变了几件让我为此工作的事情。
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:如果你想使用一个映射,则为value;如果你想使用序列,则为:1(或任何其他:你想要的名称)
这两项都适合我
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)
我简要介绍了如何使用cx_Oracle进行crud操作here。