如何解决将 cx_Oracle.LOB 结果字段更改为结果元组中的文本
我正在尝试创建一些简单的复制机制,从一个数据库中获取记录并使用 python 将其写入另一个数据库,使用 cx_oracle 查询 Oracle 源和 psycopg2 将数据插入 Postgresql
# Fetch from Oracle
cur.execute("select * from INC where sys_updated_on >= to_timestamp(:max,'YYYY-MM-DD HH24:MI:SS')",{"max": str(maxupd[0])})
# Get all records in chunks
while True:
# Fetch a subset of records acc. to cur.arraysize
records = cur.fetchmany(numRows=cur.arraysize)
# End loop if no more records are available
if not records:
break
# Get row index for unique SYS_ID
index = cols.index("SYS_ID")
# Check for each record if already exists or is new
for rec in records:
# Fetch the SYS_ID from the current record
my_sql = sql.sql("select 'SYS_ID' from inc where 'SYS_ID'= '%%%s%%' " % (rec[index]))
cur1.execute(my_sql)
myid = cur1.fetchone()
# If record does not exist in target,insert record
if myid is None:
rec = str(list(rec))[1:-1]
cur1.execute("""INSERT INTO inc VALUES(%s)""" % (rec))
由于以下错误,插入失败:
psycopg2.errors.SyntaxError: Syntax error at or near "<"
LINE 1: ...370f17e2c083d6ff7bc2050ea4','SAR',None,'4',<cx_Oracle...
这意味着将结果从元组转换为要在插入语句中使用的字符串时,无法正确读取 CLOB 字段。
像print(rec[28])
一样直接打印元组字段中的项目给出了字段的内容,但转换只显示了cx_Oracle占位符。我尝试了各种方法,但都没有达到我的目的。
有没有办法把CLOB的内容放到字符串中??
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。