【发布时间】:2012-01-27 01:29:30
【问题描述】:
我正在尝试使用 Python cx_oracle 更新表中的条目。该列名为“模板”,其数据类型为 CLOB。
这是我的代码:
dsn = cx_Oracle.makedsn(hostname, port, sid)
orcl = cx_Oracle.connect(username + '/' + password + '@' + dsn)
curs = orcl.cursor()
sql = "update mytable set template='" + template + "' where id='6';"
curs.execute(sql)
orcl.close()
当我这样做时,我收到一个错误,说字符串文字太长。模板变量包含大约 26000 个字符。我该如何解决?
编辑:
我发现了这个:http://osdir.com/ml/python.db.cx-oracle/2005-04/msg00003.html
所以我尝试了这个:
curs.setinputsizes(value = cx_Oracle.CLOB)
sql = "update mytable set template='values(:value)' where id='6';"
curs.execute(sql, value = template)
我收到“ORA-01036:非法变量名/编号错误”
编辑2:
这是我现在的代码:
curs.setinputsizes(template = cx_Oracle.CLOB)
sql = "update mytable set template= :template where id='6';"
print sql, template
curs.execute(sql, template=template)
我现在收到 ORA-00911:无效字符错误。
【问题讨论】:
-
你错误使用了参数:将
'values(:value)'改为:value(另见我的回复)