In this tutorial, I am giving an example to load BI Publisher report content to a BLOB field in Oracle Apex.
For example, you are calling a BI publisher report to generate Payslips in PDF format from the employee screen using a Print button and at the same point, you want that PDF report to load to a BLOB field into another table so that you can use it further. To perform such a task, follow these steps:
- First, create a table to store the BLOB content of a payslip PDF file. Create a table structure as follows:
CREATE TABLE EMP_PAYSLIPS (EMPNO NUMBER, FILENAME VARCHAR2(200), REPORT BLOB, MIMETYPE VARCHAR2(100), CREATED_DATE DATE, CREATED_BY VARCHAR2(100) ); ALTER TABLE EMP_PAYSLIPS ADD CONSTRAINT PK_EMPPAYSLIPS PRIMARY KEY (EMPNO);
The above table will store the payslip PDF against the employee number (EMPNO).
- Now open the page in Oracle Apex page designer in which you are calling the Payslip BI publisher report. To demonstrate this, I have created a Report Layout named Payslip and a Report Query named employee_payslip_query.
- Then call the following PL/SQL procedure from the button you are calling the BI publisher report or create a process or dynamic action, Oracle Apex has a lot of ways to do this:
declare l_report blob; begin l_report := apex_util.get_print_document ( p_application_id => :APP_ID, p_report_query_name => 'employee_payslip_query', p_report_layout_name => 'Payslip', p_report_layout_type => 'rtf', p_document_format => 'pdf' ); -- delete if already exists Delete from emp_payslips where empno = V('P3_EMPNO'); insert into emp_payslips ( empno, filename, mimetype, report, created_date, created_by ) values (V('P3_EMPNO'), 'PAYSLIP_'||V('P3_EMPNO')||'.PDF', 'application/pdf', l_report, sysdate, :USER ); EXCEPTION WHEN OTHERS THEN NULL; /* HANDLE ERROR HERE IF ANY */ end;
Note: The Report Query, and Report Layout names are case sensitive, so when calling the APEX_UTIL.GET_PRINT_DOCUMENT function, make sure to specify correct names.
Now save the changes and run the page and then query the table you will find the data inserted through the above procedure.
See also:
- How to Call BI Publisher Report from Oracle Apex?
- How to Embed BI Publisher Report into a Page in Oracle Apex?
- Oracle Apex Dynamic Popup Navigation Menu Example
Hi vinish,
I found your site as pretty useful, thanks a lot.
On this above tutorial, everything was working fine awesome man.
But, when attachment sent to email the file got corrupted. please provide any workaround for this issue.
Thanks.
Remove the exception part of the above PL/SQL program to see if any error you are getting while loading report to the table.
Because if the blob is stored properly it can be fetched via mail or using application process to display on the page. It is a tested procedure.
Thanks again, i will check that.
Hi Vinish,
As you told I removed the exception part there is no error. The file perfectly stored in a table.
But when I try to Fetch via mail or using application process to display on the page, I couldn't view the blob file.
Please provide your suggestions.
thanks.
Please check this post, in which I explained how to fetch BLOB content to display on the page using Ajax process.
Display blob contents using Ajax Process
Yes Vinish, using Ajax application process itself giving me error. I really donno what’s exactly happen.
You must be missing something.
Vinish, great job. Thank You. You really helped me get past a brick wall today with displaying image with html.