oracle提取BLOB字段文件的问题
展开全部
可以自己写个小工具,如存储过程,批量导出,如下
将存储图片的BLOB字段批量导出
--(1)生成图片存储过程
CREATE OR REPLACE PROCEDURE TMU_TMEDMS.GET_PIC_BLOB(i_xh VARCHAR2) IS
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
I_doc varchar2(50);
BEGIN
select s.content,s.doc_id into l_blob,I_doc from TMU_TMEDMS.T_TMEDMS_TM_SCAN_FILES s where s.id=i_xh;
l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
l_file := UTL_FILE.FOPEN('BLOBDIR', I_doc || '.jpg', 'WB', l_blob_len);
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);
UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
UTL_FILE.FCLOSE(l_file);
EXCEPTION
--WHEN NO_DATA_FOUND THEN
--DBMS_OUTPUT.put_line('no data : ' || i_xh);
WHEN OTHERS THEN
IF UTL_FILE.IS_OPEN(l_file) THEN
UTL_FILE.FCLOSE(l_file);
RAISE;
END IF;
END GET_PIC_BLOB;
--(2)创建导出文件存放路径
create or replace directory BLOBDIR as '/tmp/jpg';
--(3)批量导出图片SQL语句块
declare
cursor cur is
select s.id
from TMU_TMEDMS.T_TMEDMS_TM_BASE_INFO t,
TMU_TMEDMS.T_TMEDMS_TM_SCAN_FILES S
where t.flow_type_code = 'TMZC'
and t.file_type_code = 'ZCSQ'
AND T.APP_NUM >= '15823555'
AND T.APP_NUM <= '15827984'
AND substr(t.barcode, 0, 5) = 'B1011'
AND T.ID = S.DOC_ID
AND S.DOC_TYPE_CODE = 'TMIM';
begin
for rec in cur loop
TMU_TMEDMS.GET_PIC_BLOB(rec.id);
INSERT INTO record (id) VALUES (rec.id);
commit;
end loop;
end;
海枫科技
将存储图片的BLOB字段批量导出
--(1)生成图片存储过程
CREATE OR REPLACE PROCEDURE TMU_TMEDMS.GET_PIC_BLOB(i_xh VARCHAR2) IS
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
I_doc varchar2(50);
BEGIN
select s.content,s.doc_id into l_blob,I_doc from TMU_TMEDMS.T_TMEDMS_TM_SCAN_FILES s where s.id=i_xh;
l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
l_file := UTL_FILE.FOPEN('BLOBDIR', I_doc || '.jpg', 'WB', l_blob_len);
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);
UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
UTL_FILE.FCLOSE(l_file);
EXCEPTION
--WHEN NO_DATA_FOUND THEN
--DBMS_OUTPUT.put_line('no data : ' || i_xh);
WHEN OTHERS THEN
IF UTL_FILE.IS_OPEN(l_file) THEN
UTL_FILE.FCLOSE(l_file);
RAISE;
END IF;
END GET_PIC_BLOB;
--(2)创建导出文件存放路径
create or replace directory BLOBDIR as '/tmp/jpg';
--(3)批量导出图片SQL语句块
declare
cursor cur is
select s.id
from TMU_TMEDMS.T_TMEDMS_TM_BASE_INFO t,
TMU_TMEDMS.T_TMEDMS_TM_SCAN_FILES S
where t.flow_type_code = 'TMZC'
and t.file_type_code = 'ZCSQ'
AND T.APP_NUM >= '15823555'
AND T.APP_NUM <= '15827984'
AND substr(t.barcode, 0, 5) = 'B1011'
AND T.ID = S.DOC_ID
AND S.DOC_TYPE_CODE = 'TMIM';
begin
for rec in cur loop
TMU_TMEDMS.GET_PIC_BLOB(rec.id);
INSERT INTO record (id) VALUES (rec.id);
commit;
end loop;
end;
海枫科技
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询