我尝试使用cx峎oracle6.3在oracle12中插入大量blob(每个blob为2到20mb)。在
经过大量的google搜索和实验,我得到了下面的代码。我是Python新手,想知道:这种方法有效吗?有没有更快的方法?在#!/usr/local/bin/python3
import io
import os
import cx_Oracle
pdf = open('hello.pdf', 'rb')
mem_file = io.BytesIO(pdf.read())
mem_file.seek(0, os.SEEK_END)
file_size = mem_file.tell()
con = cx_Oracle.connect("user", "***", "localhost:1512/ORCLPDB1", encoding="UTF-8")
# create table for this example
con.cursor().execute("CREATE TABLE t (id NUMBER, b BLOB) LOB(b) STORE AS SECUREFILE(COMPRESS)");
# prepare cursor
cursor = con.cursor()
my_blob = cursor.var(cx_Oracle.BLOB, file_size)
my_blob.setvalue(0, mem_file.getvalue())
# execute insert
cursor.execute("INSERT INTO t(id, b) VALUES (:my_id, :my_blob)", (1, my_blob))
con.commit()
con.close()
插入一个EMPTY_BLOB()然后再做一个UPDATE怎么样?在插入之前计算BLOB的大小是否有必要/有益?在