1.用insert语句,插入clob字段,如果插入内容超过4000,会提示字符串过长,处理的方法是,先声明插入的字段为clob类型,如下:
insertSql = "DECLARE email_text clob := '%s'; begin insert into emails values ('%r','%s',email_text,'重点股票跟踪(%s)','0',''); end;" % (
email_text,id, contactEamilAddress, dateInput)
更新以上方法会报出如下错误:
cx_Oracle.DatabaseError: ORA-06550: 第 1 行, 第 28 列:
PLS-00172: string literal too long
改成如下方法即可,把参数统一放在一个数组里:
insertSql = "insert into business_EMAILS values (:1,:2,:3,:4,'0','','1','1',:5)"
params = [id, contactEamilAddress, email_text,'重点股票跟踪({0})'.format(dateInput),contactUserId]
cur.execute(insertSql,params)
conn.commit()
2.用python的结果集,读取到clob字段的时候,转化为str类型处理,如下:
cur_bbc.execute("select t.*, t.rowid from emails t where t.email_status = '0'")
res = cur_bbc.fetchall()
for record in res:
id = record[0]
to_email = record[1]
to_email_list = to_email.split(",")
email_text = record[2].read() --clob类型