cx_Oracle插入大的XMLType值

时间:2015-07-29 20:46:30

标签: python oracle cx-oracle

我有以下架构:

create table tc (c1 clob, c2 SYS.XMLTYPE)

我尝试使用此代码插入:

import cx_Oracle
conn_to = cx_Oracle.connect('user', '...', 'dbserver:1521/ENGR')

cur_to = conn_to.cursor()

insert_sql = 'insert into tc values (:val, :xmlval)'

cur_to.prepare(insert_sql)

cur_to.setinputsizes(val=cx_Oracle.CLOB, xmlval=8196)
cur_to.execute(insert_sql, {'val':('a' * 98196), 'xmlval':('<xml>' + '<inner/>' * 450 + '</xml>')})
conn_to.commit()

生成大约4963个字符的XML对象。 但是,如果我将450更改为500,则事情不再有效,我会收到错误

cx_Oracle.DatabaseError:ORA-01461:只能插入LONG值才能插入LONG列

限制似乎在5000左右,但为什么呢?

1 个答案:

答案 0 :(得分:3)

哦,等等,这是:

import cx_Oracle
conn_to = cx_Oracle.connect('user', '...', 'dbserver:1521/ENGR') 

cur_to = conn_to.cursor()

insert_sql = 'insert into tc values (:val, xmltype(:xmlval))' # need to wrap with xmltype() !

cur_to.setinputsizes(val=cx_Oracle.CLOB, xmlval=cx_Oracle.CLOB) # need to set to cx_Oracle.CLOB!
s =  ('<xml>' + '<inner/>' * 550 + '</xml>')
cur_to.execute(insert_sql, val = s, xmlval = s)

conn_to.commit()