我有一个文件.我想将其内容放入我的oracle数据库中的blob列或PL/SQL程序中的blob变量中.最好的方法是什么?
要在PL/SQL中完全执行此操作,该文件需要位于服务器上,该服务器位于您需要在数据库中定义的目录中.创建以下对象:
CREATE OR REPLACE DIRECTORY BLOB_DIR AS '/oracle/base/lobs' / CREATE OR REPLACE PROCEDURE BLOB_LOAD AS lBlob BLOB; lFile BFILE := BFILENAME('BLOB_DIR', 'filename'); BEGIN INSERT INTO table (id, your_blob) VALUES (xxx, empty_blob()) RETURNING your_blob INTO lBlob; DBMS_LOB.OPEN(lFile, DBMS_LOB.LOB_READONLY); DBMS_LOB.OPEN(lBlob, DBMS_LOB.LOB_READWRITE); DBMS_LOB.LOADFROMFILE(DEST_LOB => lBlob, SRC_LOB => lFile, AMOUNT => DBMS_LOB.GETLENGTH(lFile)); DBMS_LOB.CLOSE(lFile); DBMS_LOB.CLOSE(lBlob); COMMIT; END; /