时间:2021-07-01 10:21:17 帮助过:3人阅读
方法是先提取前2000个字符串,接着提取2000个字符串….,然后拼接起来。
import cx_Oracle import pandas as pd conn = cx_Oracle.connect("user/pwd@ip/db") # 这里只提取前6000个字符串 sql1 = "select DBMS_LOB.SUBSTR(col,2000,1) as col1 as fzss from table" # 1-2000个字符串 sql2 = "select DBMS_LOB.SUBSTR(col,4000,2001) as col2 as fzss from table" # 2001-4000个字符串 sql3 = "select DBMS_LOB.SUBSTR(col,6000,4001) as col3 as fzss from table" # 2001-4000个字符串 # 读取数据 df1 = pd.read_sql(sql1, conn) df2 = pd.read_sql(sql2, conn) df3 = pd.read_sql(sql3, conn) # 有些记录不一定是很长的字符串,结果可能是None,需要填充空字符串,否则下面的拼接会出错 df1 = df1.fillna(‘‘) df2 = df2.fillna(‘‘) df3 = df3.fillna(‘‘) # 将它们拼接起来,放在tmp字段上 df1[‘TMP‘] = df1.loc[‘COL1‘]+df2.loc[‘COL2‘]+df3.loc[‘COL3‘]
方法和将字符串导入varchar2字段是一样的,不需要特殊设置。 比如:
id=‘123‘ clob=‘a‘*2**20 # 重复2的20次方次 param=[id, colb] sql = "insert into table (id,colb) values(:1, :2)" cursor.execute(sql, param) conn.commit()
[python] python 读写Oracle clob类型数据的处理
标签:sql style import pen div pytho port param rac