Wednesday, October 12, 2011

Image/PDF data via DML


 
1.  Upload the mybook.pdf to IMAGES folder /tmp
2. Create directory in the database using Create directory images as ‘/tmp/’;
3.  Run this DML

DECLARE
    f_lob BFILE;
    b_lob BLOB;
BEGIN
    INSERT INTO dummy_table (BILLING_ID,
                                      BILLING_RUN_ID,
                                      BILLING_INFO_ID,
                                      STMT_DATA,
                                      CREATED_DATE)
    VALUES (myseqeunce.NEXTVAL,
            108,
            26753,
            EMPTY_BLOB (),
            TO_DATE ('31-AUG-2011'))
    RETURN STMT_DATA
    INTO   b_lob;

    f_lob := BFILENAME ('IMAGES', 'mybook.pdf');

    DBMS_LOB.fileopen (f_lob, DBMS_LOB.file_readonly);
    DBMS_LOB.loadfromfile (b_lob, f_lob, DBMS_LOB.getlength (f_lob));
    DBMS_LOB.fileclose (f_lob);

    COMMIT;
END;

Hope this help. Regards Rupam