数据库
首页 > 数据库> > python – cx_oracle如何更新blob列

python – cx_oracle如何更新blob列

作者:互联网

任何人都可以帮助如何更新oracle中的blob数据

所以,我想尝试:

file = open ('picture.jpg','rb') 
ext = 'jpg'
content = file.read ()
file.close ()
db = cx_Oracle.connect('user', 'pwd', dsn_tns)
db=db.cursor()
sqlStr = "update table_name set column1=:blobData, column2=" + str(ext) + " where id = 1"
db.setinputsizes (blobData = cx_Oracle.BLOB)
db.execute (sqlStr, {'blobData': content})
db.execute ('commit')
db.close()

最后,我收到了这样的错误:

cx_Oracle.DatabaseError: ORA-00904: "JPG": invalid identifier

解决方法:

file = open ('picture.jpg','rb') 
ext = 'jpg'
content = file.read ()
file.close ()
db = cx_Oracle.connect('user', 'pwd', dsn_tns)
db=db.cursor()
blobvar = db.var(cx_Oracle.BLOB)
blobvar.setvalue(0,content)
sqlStr = "update table_name set column1=:blobData, column2="jpg" where id = 1"
db.setinputsizes (blobData = cx_Oracle.BLOB)
db.execute (sqlStr, {'blobData': blobvar})
db.execute ('commit')
db.close()

标签:python,blob,cx-oracle
来源: https://codeday.me/bug/20190728/1560633.html