CREATE OR REPLACE PROCEDURE APPS.write_blob_to_file (
--p_entity_name IN VARCHAR2,
p_pk1_value IN VARCHAR2
)
AS
v_lob_loc BLOB;
v_buffer RAW (32767);
v_buffer_size BINARY_INTEGER;
v_amount BINARY_INTEGER;
v_offset NUMBER (38) := 1;
v_chunksize INTEGER;
v_out_file UTL_FILE.file_type;
v_file_name VARCHAR2 (1000);
Cursor Cur IS
SELECT fd.media_id, flb.file_data v_lob_loc, flb.file_name v_file_name
FROM fnd_lobs flb,
fnd_attached_documents fad,
fnd_documents fd
WHERE 1=1
AND fad.entity_name = 'RA_CUSTOMER_TRX'
AND fad.pk1_value = p_pk1_value
AND fad.document_id = fd.document_id
AND fd.media_id = flb.file_id;
BEGIN
-- +-------------------------------------------------------------+
-- | SELECT THE LOB LOCATOR |
-- +-------------------------------------------------------------+
DBMS_OUTPUT.put_line('File Location'||p_pk1_value);
-- +-------------------------------------------------------------+
-- | FIND OUT THE CHUNKSIZE FOR THIS LOB COLUMN |
-- +-------------------------------------------------------------+
FOR c1 in Cur
LOOP
v_chunksize := DBMS_LOB.getchunksize (c1.v_lob_loc);
IF (v_chunksize < 32767)
THEN
v_buffer_size := v_chunksize;
ELSE
v_buffer_size := 32767;
END IF;
v_amount := v_buffer_size;
-- +-------------------------------------------------------------+
-- | OPENING THE LOB IS OPTIONAL |
-- +-------------------------------------------------------------+
DBMS_LOB.OPEN (c1.v_lob_loc, DBMS_LOB.lob_readonly);
-- +-------------------------------------------------------------+
-- | WRITE CONTENTS OF THE LOB TO A FILE |
-- +-------------------------------------------------------------+
v_out_file :=
UTL_FILE.fopen
(LOCATION => '/global/erpgrp/cfs02/EBSPROD_cmlogs/conc/upload',
filename => c1.v_file_name,
open_mode => 'wb',
max_linesize => 32767
);
WHILE v_amount >= v_buffer_size
LOOP
DBMS_LOB.READ (lob_loc => c1.v_lob_loc,
amount => v_amount,
offset => v_offset,
buffer => v_buffer
);
v_offset := v_offset + v_amount;
UTL_FILE.put_raw (FILE => v_out_file,
buffer => v_buffer,
autoflush => TRUE
);
UTL_FILE.fflush (FILE => v_out_file);
END LOOP;
UTL_FILE.fflush (FILE => v_out_file);
UTL_FILE.fclose (v_out_file);
-- +-------------------------------------------------------------+
-- | CLOSING THE LOB IS MANDATORY IF YOU HAVE OPENED IT |
-- +-------------------------------------------------------------+
DBMS_LOB.CLOSE (c1.v_lob_loc);
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line('No file found with Given Entity Name and PK1_Value'||SQLERRM);
END write_blob_to_file;
/
--p_entity_name IN VARCHAR2,
p_pk1_value IN VARCHAR2
)
AS
v_lob_loc BLOB;
v_buffer RAW (32767);
v_buffer_size BINARY_INTEGER;
v_amount BINARY_INTEGER;
v_offset NUMBER (38) := 1;
v_chunksize INTEGER;
v_out_file UTL_FILE.file_type;
v_file_name VARCHAR2 (1000);
Cursor Cur IS
SELECT fd.media_id, flb.file_data v_lob_loc, flb.file_name v_file_name
FROM fnd_lobs flb,
fnd_attached_documents fad,
fnd_documents fd
WHERE 1=1
AND fad.entity_name = 'RA_CUSTOMER_TRX'
AND fad.pk1_value = p_pk1_value
AND fad.document_id = fd.document_id
AND fd.media_id = flb.file_id;
BEGIN
-- +-------------------------------------------------------------+
-- | SELECT THE LOB LOCATOR |
-- +-------------------------------------------------------------+
DBMS_OUTPUT.put_line('File Location'||p_pk1_value);
-- +-------------------------------------------------------------+
-- | FIND OUT THE CHUNKSIZE FOR THIS LOB COLUMN |
-- +-------------------------------------------------------------+
FOR c1 in Cur
LOOP
v_chunksize := DBMS_LOB.getchunksize (c1.v_lob_loc);
IF (v_chunksize < 32767)
THEN
v_buffer_size := v_chunksize;
ELSE
v_buffer_size := 32767;
END IF;
v_amount := v_buffer_size;
-- +-------------------------------------------------------------+
-- | OPENING THE LOB IS OPTIONAL |
-- +-------------------------------------------------------------+
DBMS_LOB.OPEN (c1.v_lob_loc, DBMS_LOB.lob_readonly);
-- +-------------------------------------------------------------+
-- | WRITE CONTENTS OF THE LOB TO A FILE |
-- +-------------------------------------------------------------+
v_out_file :=
UTL_FILE.fopen
(LOCATION => '/global/erpgrp/cfs02/EBSPROD_cmlogs/conc/upload',
filename => c1.v_file_name,
open_mode => 'wb',
max_linesize => 32767
);
WHILE v_amount >= v_buffer_size
LOOP
DBMS_LOB.READ (lob_loc => c1.v_lob_loc,
amount => v_amount,
offset => v_offset,
buffer => v_buffer
);
v_offset := v_offset + v_amount;
UTL_FILE.put_raw (FILE => v_out_file,
buffer => v_buffer,
autoflush => TRUE
);
UTL_FILE.fflush (FILE => v_out_file);
END LOOP;
UTL_FILE.fflush (FILE => v_out_file);
UTL_FILE.fclose (v_out_file);
-- +-------------------------------------------------------------+
-- | CLOSING THE LOB IS MANDATORY IF YOU HAVE OPENED IT |
-- +-------------------------------------------------------------+
DBMS_LOB.CLOSE (c1.v_lob_loc);
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line('No file found with Given Entity Name and PK1_Value'||SQLERRM);
END write_blob_to_file;
/