Python 插入长文本至Oracle

2021-11-20  本文已影响0人  逍遥_yjz

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

首先插入数据,在已有数据的基础上,更新插入剩余数据。
字符串拼接,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))
上一篇 下一篇

猜你喜欢

热点阅读