问题描述
我正在尝试创建一些简单的复制机制,从一个数据库中获取记录并使用 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 (将#修改为@)