This tutorial shows you how to create a PDF report that contains a table and graph utilizing two report queries.
Approximately 1 hour
A Report Query can contain more than one query. This allows you to easily create a PDF file that contains the results of multiple queries. In this tutorial, you will create a Report Query with two queries. The Report Layout consists of a table and a graph in one report layout. When the report is executed, the PDF file will contain two reports in the one document.
In this section, you create a Report Query with multiple queries. Perform the following steps:
1 . |
Enter the following URL to log in to Oracle Application Express.
|
---|---|
2 . |
On the Workspace home page, click Application Builder.
|
3 . |
Select Printing Application.
|
4 . |
Click Shared Components.
|
5 . |
Under Reports, click Report Queries.
|
6 . |
Click Create.
|
7 . |
Enter multiquery for the Name and click Next.
|
8 . |
Click Query Builder to create the query.
|
9 . |
From the list of queries, select OEHR_EMPLOYEES.
|
10 . |
Select the check box in front of each of the following columns and click Return. FIRST_NAME LAST_NAME EMAIL HIRE_DATE JOB_ID SALARY
|
11 . |
Your SQL Query is shown. Click Next.
|
12 . |
You want to add another query, click Add Query.
|
13 . |
Click Query Builder again.
|
14 . |
Select OEHR_DEPARTMENTS and OEHR_EMPLOYEES.
|
15 . |
To create the join condition, drag OEHR_DEPARTMENTS.MANAGER_ID over OEHR_EMPLOYEES.EMPLOYEE_ID.
|
16 . |
Select the check box in front of each of the following columns and click Return. OEHR_DEPARTMENTS.DEPARTMENT_NAME OEHR_DEPARTMENTS.MANAGER_ID OEHR_EMPLOYEES.FIRST_NAME OEHR_EMPLOYEES.LAST_NAME OEHR_EMPLOYEES.SALARY
|
17 . |
To create the query, click Create.
|
18 . |
The queries have been defined. In the next section of this tutorial, you create the report layout using Oracle BI Publisher Desktop.
|
In this section, you create a Report Layout based on the multiple queries using Oracle BI Publisher Desktop. Perform the following steps
1 . |
From the Source Queries page in the Report Query wizard, click Download.
|
---|---|
2 . |
Click Save and save the file as the default name multiquery.xml. Then close the download window.
|
3 . |
Open Microsoft Word. Select Oracle BI Publisher > Data > Load Sample XML Data...
|
4 . |
Select multiquery.xml from the apex directory and click Open.
|
5 . |
The data was loaded successfully. click OK.
|
6 . |
Select Oracle BI Publisher > Insert > Table/Form...
|
7 . |
You want all the columns under Rowset1Row to appear in the table. Drag Rowset1 Row to the Template area.
|
8 . |
Select Drop All Nodes.
|
9 . |
To create the table, click OK.
|
10 . |
The table is shown.
|
11 . |
Resize the columns and add a Title.
|
12 . |
You now want to create a chart using the second query. Select Oracle BI Publisher > Insert > Chart...
|
13 . |
Under Rowset2 Row, drag Salary to Values.
|
14 . |
Drag Department Name to Labels.
|
15 . |
Select Pie Chart for Type. Scroll down to the Title field and enter Total Salary Percentage by Department. Click OK.
|
16 . |
The chart is displayed.
|
17 . |
You need to save your layout as an RTF file. Select File > Save As... Select Rich Text Format (*.rtf) for Save as Type, enter multiquery.rtf for File Name, place the file in the apex directory and click Save.
|
18 . |
Switch back to Application Express and click Next.
|
19 . |
Click Browse... to select the RTF file you just created. Select the multiquery.rtf file from the apex directory and click Open.
|
20 . |
Click Next.
|
21 . |
In order to test your report, you need to first start BI Publisher. Double-click the Start BI Publisher icon on your desktop.
|
22 . |
To test your report, click Test Report.
|
23 . |
When the dialogue appears, click Open.
|
24 . |
The table is populated with data, scroll down to see the chart.
|
25 . |
Close the PDF report. On the Create Shared Query page, click Finish.
|
26 . |
Your Report Query and Report Layout were created successfully. In the next section, you create a button on a page that invokes the report.
|
In this section, you invoke the report query from a page in your application. Perform the following steps:
1 . |
Navigate to your Printing Application page. Click the Home page.
|
---|---|
2 . |
Click the Create Button icon.
|
3 . |
Select the Home region and click Next.
|
4 . |
Accept the default and click Next.
|
5 . |
Enter Print Report for Button Name and select Download printable report query for Action and click Next.
|
6 . |
Accept the default and click Next.
|
7 . |
Select [Top] from the list of quick links or select Top of Region from the drop down list and select Left for Alignment and click Next.
|
8 . |
Select multiquery for the Report Query and click Create Button.
|
9 . |
Your button was created successfully. Click Run.
|
10 . |
You may be asked to login to the application. Enter obe/obe and click Login.
|
11 . |
Click Print Report.
|
12 . |
Click Open to open the PDF report.
|
13 . |
The report is displayed.
|
You can dynamically include images in your application. In this section of the tutorial, you create a report query and layout that dynamically includes images in a PDF report.
In this section, you alter the OEHR_EMPLOYEES table and add a BLOB column and load it with data. Perform the following steps:
1 . |
Open a DOS command prompt and execute the addblobdata.sql script. cd apex
|
---|---|
2 . |
To view the data in the OEHR_EMPLOYEES table, Enter the following URL to log in to Oracle Application Express. http://localhost:8080/apex
|
3 . |
Select the Home region and click Next.
|
4 . |
To log in to Oracle Application Express, enter the following details, and click Login.
|
5 . |
On the Workspace home page, click SQL Workshop.
|
6 . |
Click Object Browser.
|
7 . |
Select OEHR_EMPLOYEES from the list of tables. Notice that the additional BLOB columns are now listed. Select the Data tab.
|
8 . |
Scroll left to see the data for employees 101 and 103.
|
9 . |
Notice that there is data for the FILENAME and MIMETYPE columns.
|
In order to include the BLOB in your PDF report, the data needs to be converted to CLOB base 64 encoded format. You will create a function to perform the conversion. Perform the following steps:
1 . |
Select SQL Scripts from the list of Components.
|
---|---|
2 . |
Click Upload.
|
3 . |
Click Browse... and select the blob2clobase64.sql file and click Open.
|
4 . |
Click Upload.
|
5 . |
Click the script icon.
|
6 . |
Click Run.
|
7 . |
Click Run to confirm .
|
8 . |
Click the View Results icon.
|
9 . |
The blob2clobase64 function was created successfully.
|
In this section, you create a Report Query and a Report Layout. Perform the following steps:
1 . |
Navigate to the Application Builder. Select the Printing Application.
|
---|---|
2 . |
Click Shared Components.
|
3 . |
Under Reports, click Report Queries.
|
4 . |
Click Create.
|
5 . |
Enter blobquery for the Name and click Next.
|
6 . |
Enter the following query and click Next. Notice that the SQL statement invokes the function you created in the previous section to convert the BLOB column PHOTO to CLOB based 64 encoded format. select
|
7 . |
Your query was created. Click Next.
|
8 . |
Click Browse... and select the bloblist2.rtf file and click Open.
|
9 . |
Click Next.
|
10 . |
If you haven't done so already, you need to first start BI Publisher. Double-click the Start BI Publisher icon on your desktop.
|
11 . |
Click Test Report.
|
12 . |
Click Open.
|
13 . |
The report is shown. When done viewing the report, close the window.
|
14 . |
Click Finish.
|
15 . |
Your Report Query and Report Layout were created successfully. In the next section, you create a button on your page to run the report. Select your Application breadcrumb.
|
In this section, you invoke the report query from a page in your application. Perform the following steps:
1 . |
Navigate to your Printing Application page. Click the Home page.
|
---|---|
2 . |
Click the Create Button icon.
|
3 . |
Select the Home region and click Next.
|
4 . |
Accept the default and click Next.
|
5 . |
Enter Print Report with Images for Button Name and select Download printable report query for Action and click Next.
|
6 . |
Accept the default and click Next.
|
7 . |
Select [Top] from the list of quick links or select Top of Region from the drop down list and select Left for Alignment and click Next.
|
8 . |
Select blobquery for the Report Query and click Create Button.
|
9 . |
Your button was created successfully. Click Run.
|
10 . |
You may be asked to login to the application. Enter obe/obe and click Login.
|
11 . |
Click Print Report With Images.
|
12 . |
Click Open to open the PDF report.
|
13 . |
The report is displayed.
|
You can store a report in a BLOB column in your database. In this section of the tutorial, you will create a new table to store the reports that are generated and then create a report of the contents of the table.
In this section, you upload and run a script that creates a table to store the reports that you generate. Perform the following steps:
1 . |
Open your browser and enter the following URL to log in to Oracle Application Express. http://localhost:8080/apex
|
---|---|
2 . |
To log in to Oracle Application Express, enter the following details, and click Login.
|
3 . |
Click the SQL Workshop tab. Then click SQL Scripts.
|
4 . |
Click Upload.
|
5 . |
Click Browse... and select the report_archive_tbl.sql file and click Open.
|
6 . |
Click Upload.
|
7 . |
Click the report_archive_tbl.sql script icon.
|
8 . |
Click Run.
|
9 . |
Click Run to confirm.
|
10 . |
Click the View Results icon.
|
11 . |
The report_archive table was created successfully.
|
In this section, you create a process that stores the report in the database. Perform the following steps:
1 . |
Navigate to the Application Builder. Select the Printing Application.
|
---|---|
2 . |
Click the Home page.
|
3 . |
You need to create a process that will store the report in the database. Under Processes, click the Create icon.
|
4 . |
Select PL/SQL and click Next.
|
5 . |
Enter store_blobquery_report for the Name and click Next.
|
6 . |
Enter the following code in the PL/SQL Page Process area and click Next. declare l_report blob; begin l_report := apex_util.get_print_document ( p_application_id => :APP_ID, p_report_query_name => 'blobquery', p_report_layout_name => 'blobquery', p_report_layout_type => 'rtf', p_document_format => 'pdf' ); insert into report_archive ( filename, mimetype, report, created_date, created_by ) values ( 'BLOB Query Search Results ('||to_char(sysdate,'DDMonYYYY')||')', 'application/pdf', l_report, sysdate, :USER ); end;
|
7 . |
Click Next.
|
8 . |
Select PRINT_REPORT_WITH_IMAGES for When Button Pressed and click Create Process.
|
9 . |
You also want to create a process to store the Multi Query report. Under Processes, click the Create icon.
|
10 . |
Select PL/SQL and click Next.
|
11 . |
Enter store_multiquery_report for the Name and click Next.
|
12 . |
Enter the following code in the PL/SQL Page Process area and click Next. declare
|
13 . |
Click Next.
|
14 . |
Select PRINT_REPORT for When Button Pressed and click Create Process.
|
15 . |
Click Run.
|
16 . |
Click Print Report With Images. When the dialogue to open or save the report appears, you can click Cancel.
|
17 . |
Click Print Report. When the dialogue to open or save the report appears, you can click Cancel. Note: Two rows were inserted into the database for each report you ran.
|
In this section, you create a report of the data in the report_archive table in the database. Perform the following steps:
1 . |
Navigate to your Printing Application page. Click the Home page.
|
---|---|
2 . |
Under Regions, click the Create icon.
|
3 . |
Select Report and click Next.
|
4 . |
Make sure SQL Report is selected and click Next.
|
5 . |
Enter List of Stored Reports for Title and click Next.
|
6 . |
Enter the following SQL in the SQL Query area and click Create Region. SELECT id, filename, mimetype, created_date, created_by, dbms_lob.getlength(report) report_length FROM report_archive
|
7 . |
The report was created. You need to make a few changes to the Report Attributes. Under Regions, select the Report link.
|
8 . |
Under Headings Type, click Custom. Change the name of the Report Length header to Report. Deselect the Show check box for MIMETYPE. You also want to create a link to download the report in the Report Length column. Select the edit icon for Report Length.
|
9 . |
Under Column Formatting, enter the following string in the Number / Date Format field and click Apply Changes. DOWNLOAD:REPORT_ARCHIVE:REPORT:ID::MIMETYPE:FILENAME:::inline:[Download]Note this string contains the following parameters: <Format Mask>:<BLOB Table>:<BLOB Column>:<Primary Key Column 1>::<MIME Type Column>: <Filename Column>:::<Content Disposition>:<Download Link Text>
|
10 . |
Click Run Page.
|
11 . |
The list of reports that you ran in the previous section of this tutorial are in the list. To view a report, click the [Download] link.
|
12 . |
The report is displayed successfully.
|
You can create multiple report layouts that an end-user can select from when executing the report. In this section of the tutorial, you create two Report Layouts. From a page in your application, you create a radio group of the Report Layouts available. When the page is executed, you select which layout you want to use when the report is generated.
In this section, you create multiple report layouts. Perform the following steps:
1 . |
Open your browser and enter the following URL to log in to Oracle Application Express .http://localhost:8080/apex
|
---|---|
2 . |
To log in to Oracle Application Express, enter the following details, and click Login.
|
3 . |
On the Workspace home page, click Application Builder.
|
4 . |
Select Printing Application.
|
5 . |
Click Shared Components.
|
6 . |
Under Reports, click Report Layouts.
|
7 . |
Click Create.
|
8 . |
Select Named Columns (RTF) and click Next.
|
9 . |
Enter DynamicLayout1 for the Name and click Browse...
|
10 . |
Select Dynamic_Layout1.rtf from the apex directory and click Open.
|
11 . |
Click Create Layout.
|
12 . |
You want to create another report layout. click Create.
|
13 . |
Select Named Columns (RTF) and click Next.
|
14 . |
Enter DynamicLayout2 for the Name and Click Browse...
|
15 . |
Select Dynamic_Layout2.rtf from the apex directory and click Open.
|
16 . |
Click Create Layout.
|
17 . |
You also need to create a report query that the report layouts will be based on. Select the Shared Components breadcrumb.
|
18 . |
Under Reports, select Report Queries.
|
19 . |
Click Create.
|
20 . |
Enter DynamicQuery for the Name and click Next.
|
21 . |
Enter the following query and click Next. SELECT first_name, last_name, email, hire_date, salary FROM oehr_employees
|
22 . |
Click Next.
|
23 . |
Select Use generic report layout for Report Layout Source and click Next.
|
24 . |
Click Finish.
|
25 . |
Your report query was created successfully. In the next section, you create the items the user selects that dynamically generate the report.
|
In this section, you create multiple report layouts. Perform the following steps:
1 . |
Navigate to the Print Application Application Page. Select the Home page.
|
||||||
---|---|---|---|---|---|---|---|
2 . |
Under Regions, select the Create icon.
|
||||||
3 . |
Select HTML and click Next.
|
||||||
4 . |
Select HTML again and click Next.
|
||||||
5 . |
Enter Dynamic Report Generation for the Title and click Next.
|
||||||
6 . |
You now need to create a few items that will be used to generate the report. The first item is a hidden and protected item to store the report query. Under Items, click the Create icon.
|
||||||
7 . |
Select the Hidden item type and click Next.
|
||||||
8 . |
Select Hidden and Protected and click Next.
|
||||||
9 . |
Enter P1_REPORT_QUERY for the Item Name, select Dynamic Report Generation for the Region and click Next.
|
||||||
10 . |
Click Next.
|
||||||
11 . |
Enter DynamicQuery for Item Source Query and click Create Item.
|
||||||
12 . |
The next item you will create is a select list that allows the user to select how the report should be displayed, in the browser or as an attachment file that can be displayed in Acrobat Reader. Under Items, click the Create icon.
|
||||||
13 . |
Select the Select List item type and click Next.
|
||||||
14 . |
Select Select List again and click Next.
|
||||||
15 . |
Enter P1_CONTENT_DISP for the Item Name, select Dynamic Report Generation for the Region and click Next.
|
||||||
16 . |
Select No for Display Null Option and select the Create or edit static List of Values.
|
||||||
17 . |
Enter the following values and click Apply.
|
||||||
18 . |
Click Next.
|
||||||
19 . |
Enter Display for the Label and click Next.
|
||||||
20 . |
Click Create Item.
|
||||||
21 . |
The last item you create is a radio group that shows the list of report layouts to choose from. Under Items, select the Create icon.
|
||||||
22 . |
Select Radio and click Next.
|
||||||
23 . |
Select Radio Group and click Next.
|
||||||
24 . |
Enter P1_REPORT_LAYOUT for the Item Name, select Dynamic Report Generation for the Region and click Next.
|
||||||
25 . |
Select No for Display Null Option and select the Create or edit static List of Values.
|
||||||
26 . |
Enter the following values and click Apply.
|
||||||
27 . |
Click Next.
|
||||||
28 . |
Accept the defaults and click Next.
|
||||||
29 . |
Enter DynamicLayout1 for the Default and click Create Item.
|
||||||
30 . |
You now need to create a button the will invoke a process (that you will create after the button is created) to generate the report. Under Buttons, click the Create icon.
|
||||||
31 . |
Select the Dynamic Report Generation region and click Next.
|
||||||
32 . |
Accept the default and click Next.
|
||||||
33 . |
Enter Print for the Button Name and click Next.
|
||||||
34 . |
Accept the default and click Next.
|
||||||
35 . |
Select [Top] from the list of quick links or select Top of Region from the drop down list and select Left for Alignment and click Next.
|
||||||
36 . |
Click Create Button.
|
||||||
37 . |
The last component you need to create is the process that is invoked when the Print button is pressed to generate the report. Under Processes, click the Create icon.
|
||||||
38 . |
Select PL/SQL and click Next.
|
||||||
39 . |
Enter print for the Name and click Next.
|
||||||
40 . |
Enter the following code and click Next. Notice that this code executes the download_print_document API to generate the report. The report will be generated based on the values specified from the user for the items on the page. apex_util.download_print_document (
p_file_name => 'myreport123',
p_content_disposition => :P1_CONTENT_DISP,
p_application_id => :APP_ID,
p_report_query_name => :P1_REPORT_QUERY,
p_report_layout_name => :P1_REPORT_LAYOUT,
p_report_layout_type => 'rtf',
p_document_format => 'pdf'
);
|
||||||
41 . |
Click Next.
|
||||||
42 . |
Select Print for When Button Pressed and click Create Process. In the next section, you run the page and generate the report.
|
In this section, you run the page to generate the report. Perform the following steps:
1 . |
Click Run.
|
---|---|
2 . |
Select Save / Open in Separate Window and click Print.
|
3 . |
The report was generated. Click Open to view the report.
|
4 . |
The report is displayed with Dynamic Layout 1. Close the report.
|
5 . |
Select In Browser for Display, select Dynamic Layout 2 and click Print.
|
6 . |
This time, your report was displayed within the browser with Dynamic Layout 2.
|
In this tutorial, you should have learned how to:
![]() |
About
Oracle |Oracle and Sun | ![]() |