DECLARE
v_src_loc BFILE := BFILENAME ('ORACLE_DIR', 'FILE_NAME');
v_amount INTEGER;
v_b BLOB;
BEGIN
DBMS_LOB.OPEN (v_src_loc, DBMS_LOB.LOB_READONLY);
v_amount := DBMS_LOB.GETLENGTH (v_src_loc);
UPDATE BLOB_TABLE
SET BLOB_COLUMN = EMPTY_BLOB ()
RETURNING BLOB_COLUMN
INTO v_b;
DBMS_LOB.LOADFROMFILE (v_b, v_src_loc, v_amount);
DBMS_LOB.CLOSE (v_src_loc);
commit;
END;
/
Monday, January 19, 2015
PL SQL procedure to extract a BLOB to a Filesystem
This PL SQL procedure allows you to extract a BLOB column to FS
DECLARE
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW (32767);
l_amount BINARY_INTEGER := 32767;
l_pos NUMBER := 1;
l_blob BLOB;
l_blob_len NUMBER;
BEGIN
SELECT YOUR_BLOB_COLUMN
INTO l_blob
FROM YOU_BLOB_TABLE;
l_blob_len := DBMS_LOB.getlength (l_blob);
-- Open the destination file.
l_file :=
UTL_FILE.fopen ('ORACLE_DIR',
'FILE_NAME',
'wb',
32767);
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;
-- Close the file.
UTL_FILE.fclose (l_file);
END;
DECLARE
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW (32767);
l_amount BINARY_INTEGER := 32767;
l_pos NUMBER := 1;
l_blob BLOB;
l_blob_len NUMBER;
BEGIN
SELECT YOUR_BLOB_COLUMN
INTO l_blob
FROM YOU_BLOB_TABLE;
l_blob_len := DBMS_LOB.getlength (l_blob);
-- Open the destination file.
l_file :=
UTL_FILE.fopen ('ORACLE_DIR',
'FILE_NAME',
'wb',
32767);
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;
-- Close the file.
UTL_FILE.fclose (l_file);
END;
Subscribe to:
Posts (Atom)