美文网首页
Python 插入长文本至Oracle

Python 插入长文本至Oracle

作者: 逍遥_yjz | 来源:发表于2021-11-20 14:49 被阅读0次

使用Oracle在更新某个字段的时候,报错ORA-01704: string literal too long。
解决办法:

  • 1,首先查看该字段的类型,确定字段类型是CLOB(4000),而不是VARCHAR2。
  • 2,此时是在不行,就只能分两次更新该字段了。

首先插入数据,在已有数据的基础上,更新插入剩余数据。
字符串拼接,update使用字符串拼接

update test set PROJECT='370700,81862017,624C0105' where id=1;  
update test set PROJECT=PROJECT || ',624C0105' where id=1;  

或者:

# 例子1
insert_base_sql = "INSERT INTO TP_ER(UUID,PROJECT,PRONUM,BID_RIGING,NUM,LIFT,TM) VALUES ('%s',:blobData,'%s','%s','%s','%s','%s')" % (
    ID, pro_num, br_company, num, lift, TM)
cursor.setinputsizes(blobData=cx_Oracle.CLOB)
cursor.execute(insert_base_sql,{'blobData': project})
conn.commit()

# 例子2
insert_base_sql = "INSERT INTO TP_ER(UUID,PROJECT,PRONUM,BID_RIGING,NUM,LIFT,TM) VALUES (:ID, :project,:pro_num, :br_company, :num, :lift, :TM)"

cursor.execute(insert_base_sql,(ID, project, pro_num, br_company, num, lift, TM))
conn.commit()
if not values_warning_words:
    sql = "INSERT INTO WT_SATELITECLOUD_T(SL_ID,SL_TIME,CREATE_TIME,SL_FILETYPE,BFILE,DATA_TYPE,DATA_SOURCE) VALUES(:SL_ID,:SL_TIME,:CREATE_TIME,:SL_FILETYPE,:BFILE,:DATA_TYPE,:DATA_SOURCE)"
    cursor.execute(sql, (SL_ID, SL_TIME, CREATE_TIME, SL_FILETYPE, BFILE, DATA_TYPE, DATA_SOURCE))

else:
    sql = "UPDATE WT_SATELITECLOUD_T SET CREATE_TIME=:CREATE_TIME,SL_FILETYPE=:SL_FILETYPE,BFILE=:BFILE WHERE SL_TIME=:SL_TIME and DATA_TYPE=:DATA_TYPE"
    cursor.execute(sql, (CREATE_TIME, SL_FILETYPE, BFILE, SL_TIME, DATA_TYPE))

相关文章

网友评论

      本文标题:Python 插入长文本至Oracle

      本文链接:https://www.haomeiwen.com/subject/xxzytrtx.html