gpt4 book ai didi

python - cx_oracle 如何更新 blob 列

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:53 26 4
gpt4 key购买 nike

谁能帮忙更新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 - cx_oracle 如何更新 blob 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27010588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com