BEGIN
Loading_BLOB_From_File('USER_DIR', '12345.txt',12345);END;
=================================================
Creating a Temp directory where the file can be placed..
=================================================
CREATE OR REPLACE DIRECTORY USER_DIR AS '/usr/tmp';
GRANT ALL on DIRECTORY USER_DIR TO PUBLIC; =================================================
CREATE OR REPLACE PROCEDURE Loading_BLOB_From_File ( P_DIR IN VARCHAR2
,P_FILE_NAME IN VARCHAR2
,p_rowid IN VARCHAR2)
AS
dest_loc BLOB;
src_loc BFILE := BFILENAME(P_DIR, P_FILE_NAME);
BEGIN
-- +-------------------------------------------------------------+
-- | INSERT INITIAL BLOB VALUE (an text file) INTO THE TABLE |
-- +-------------------------------------------------------------+
DBMS_OUTPUT.put_line ('Before Updating');
update XX_FILE_TABLE
set TEXT = EMPTY_BLOB()
where rowid = P_rowid
RETURNING text INTO dest_loc;
DBMS_OUTPUT.put_line ('after Updating');
-- +-------------------------------------------------------------+
-- | OPENING THE SOURCE BFILE IS MANDATORY |
-- +-------------------------------------------------------------+
DBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY);
DBMS_OUTPUT.put_line ('src_loc open');
-- +-------------------------------------------------------------+
-- | OPENING THE LOB IS OPTIONAL |
-- +-------------------------------------------------------------+
DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);
DBMS_OUTPUT.put_line ('dest_loc open');
-- +-------------------------------------------------------------+
-- | SIMPLY CALL "loadfromfile" TO LOAD FILES INTO A LOB COLUMN |
-- +-------------------------------------------------------------+
DBMS_LOB.LOADFROMFILE(
dest_lob => dest_loc
, src_lob => src_loc
, amount => DBMS_LOB.getLength(src_loc));
DBMS_OUTPUT.put_line ('dest_loc load file');
-- +-------------------------------------------------------------+
-- | CLOSING ANY LOB IS MANDATORY IF YOU HAVE OPENED IT |
-- +-------------------------------------------------------------+
DBMS_LOB.CLOSE(dest_loc);
DBMS_LOB.CLOSE(src_loc);
DBMS_OUTPUT.put_line ('close all db');
COMMIT;
Exception
when others then
DBMS_OUTPUT.put_line (' Exception in Loading_BLOB_From_File'||SQLERRM);
END Loading_BLOB_From_File;
/
Thank you..
Sal..
No comments:
Post a Comment