我使用python使用cx_Oracle
将数据插入XMLType表import cx_Oracle
import pprint
db = cx_Oracle.connect('scott','tiger','localhost:1521/orcl1')
cursor = db.cursor()
cursor.setinputsizes(xml_clob=cx_Oracle.CLOB)
cursor.execute("insert into xmltable values (xmltype(:xml_clob))",xml_clob='<name>Kathy Smith</name>')
cursor.setinputsizes(cx_Oracle.CLOB)
cursor.prepare('insert into xmltable values (xmltype(:1))')
xml_clob = '<name>Kathy Smith</name>'
cursor.execute(None,(xml_clob))
最终我想使用cursor_executemany从列表中插入。
此作品
cursor.execute("insert into xmltable values (xmltype(:xml_clob))",xml_clob='<name>Kathy Smith</name>')
这并不是
----> 1 cursor.execute(None,(xml_clob))
DatabaseError: ORA-01036: illegal variable name/number
我的xml文件包含许多记录,如下所示,我将读入列表并使用executemany
<customerinfo xmlns:ns0="http://posample.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Cid="1000">
<name>Kathy Smith</name>
<addr country="Canada">
<street>5 Rosewood</street>
<city>Toronto</city>
<prov-state>Ontario</prov-state>
<pcode-zip>M6W 1E6</pcode-zip>
</addr>
<contacts>
<phone type="work">416-555-1358</phone>
<emails>
<email1>kathy@stackoverflow.org</email1>
<email2>kathy@stackover.org</email2>
</emails>
<phone type="personal">416-555-1358</phone>
<emails>
<email1>kathy@stackoverflow.org</email1>
<email2>kathy@stackover.org</email2>
</emails>
</contacts>
</customerinfo>