1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
DECLARE
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;
v_varchar VARCHAR2(32767);
BEGIN
-- Get LOB locator
SELECT content
INTO l_blob
FROM FND_LOG_ATTACHMENTS
WHERE rownum = 1;
l_blob_len := DBMS_LOB.getlength(l_blob);
dbms_output.put_line('Internal LOB size is: ' || l_blob_len);
-- Open the destination file.
l_file := UTL_FILE.fopen('BLOBS','TEST.TXT','w', 32767);
-- Read chunks of the BLOB and write them to the file
-- until complete.
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);
--utl_file.put(l_file, UTL_RAW.CAST_TO_VARCHAR2(l_buffer) );
l_pos := l_pos + l_amount;
END LOOP;
-- Close the file.
UTL_FILE.fclose(l_file);
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open(l_file) THEN
UTL_FILE.fclose(l_file);
END IF;
RAISE;
END;
/ |
Partager