You are on page 1of 9

School of Computer Sciences, USM, Penang

CMT221/CMM222: Database Organization and Design

Academic Session: Semester 1, 2017/2018

Lab 05 Creating Reports using the Oracle SQL Developer

I. Objectives
At the end of today session, you should be able to perform the following:
Create tabular reports using the Oracle SQL Developer.
Create charts (i.e. bar and pie charts) using the Oracle SQL Developer.
Export reports (e.g. tabular reports and charts) to HTML and PDF.

II. Introduction
In today lab session, you will learn how to use the reporting tools in Oracle SQL developer to generate various
types of report. In specific, you will learn how to create a tabular report, a bar chart and a pie chart. These
reports will then be saved as a HTML and PDF.

You will be given a dataset in Excel format (Miniature.xlsx), which is downloadable from the
eLearn@USM. It consists of 30 rows of miniature sales of a company in different areas in Malaysia. Import the
dataset into the Oracle Database Express Edition 11g using Oracle SQL Developer. Name the table as
MINIATURE and the table should have a structure of six columns (i.e. TEAM, AREA, ORDERID, PRODUCT,
PRICE, and QUANTITY). Note that the data type for the PRICE and QUANTITY columns is Number and
Integer respectively. Further information on how to import data into the Oracle Database Express Edition
11g using Oracle SQL Developer can be found in Lab 03.

Check the existence of the Miniature table by expanding the Tables under the LOCAL connection instance.
The Miniature table is with 30 rows as shown in Figure 1.

Figure 1: The MINIATURE table with 30 rows

Page | 1 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
III. Creating Tabular Report
Consider a scenario as follows. Lets imagine that the boss of the miniature sales company would like to see a
tabular report which contains of the revenue generated by the WLP sales team in different areas. The data must
be sorted in descending order in terms of revenue. In order to create such tabular report, follow the steps below:
a. Click the Reports pane if it is visible. If it is not, select View > Reports. The Reports pane is
displayed.
b. In the Reports pane, right click User Defined Reports, and select New Report as shown in
Figure 2.
c. The Create Report dialog box displays Master Report properties as shown in Figure 3. Connect
to the LOCAL schema and select the Advanced check box. The Master Report tree is displayed.

Figure 2: New Report in the Reports pane.

Figure 3: Create Report dialog box.

Page | 2 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
d. For the report name, enter Sales Revenue Generated by WLP Team. See Figure 4.
e. For the report style, select Table. See Figure 4.
f. It is optional to enter the report description and tool tip.

Figure 4: Specifying report name and report style.

g. In Master Report, click SQL Query as shown in Figure 5.


h. Enter the following SQL statement to generate the tabular report.

SELECT AREA, SUM(PRICE*QUANTITY) AS REVENUE FROM MINIATURE


WHERE TEAM='WLP' GROUP BY AREA ORDER BY REVENUE DESC;

Figure 5: SQL Query in Master Report.

i. Make sure the LOCAL schema is connected. Click Test Report and verify the output.
j. Click Apply to generate the report.
k. In the Reports pane, right click Sales Revenue Generated by WLP Team, and select HTML.
l. The Generate HTML dialog box is displayed as shown in Figure 6. Connect to LOCAL schema, provide
the destination of the HTML file, and check the two check boxes. Click Apply.
m. A report in HTML is displayed as shown in Figure 7.

Congratulations! You have learned how to generate a tabular report using Oracle SQL Developer and save the
tabular report in HTML format.

Page | 3 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
Figure 6: The Generate HTML dialog box.

Figure 7: The Generate HTML dialog box.

You can use SQL Developer to create PDF versions of the Sales Revenue Generated by WLP Team
report and add password protection for the mentioned report. In order to do so, follow the steps below:
a. In the Reports pane, under the User Defined Reports, right click the Sales Revenue
Generated by WLP Team report which you created previously and select Edit.
b. In the Master Report tree, expand PDF to reveal the settings that can be applied to your PDF
reports. There are seven different settings under the PDF, namely: Binary Large Object, Cell
Layout, Column Layout, Table Layout, Header and Footer, Security, and Page
Layout. In this lab session, Column Layout, and Header and Footer are focused.
c. Click Column Layout. Select All Pages for the Header to provide a header on each page of the
report. See Figure 8.

Figure 8: The Column Layout setting for PDF report.

Page | 4 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
d. Click Header and Footer. Select the Include Header and Include Footer check boxes.
Prepare the settings according to Figure 9. Remember to insert page number at report generate time
for the report footer.

Figure 9: The Header and Footer setting for PDF report.

e. Click Apply. When the Sales Revenue Generated by WLP Team report is opened, you can
export it into PDF. Right-click inside the Sales Revenue Generated by WLP Team report and
select Export. See Figure 10.

Figure 10: Exporting to PDF.

f. Export Wizard is showed. Select pdf for the format. It is optional to provide title, subject, and keywords.

Page | 5 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
g. Specify the name of the PDF report and the location of the saved report in File text box. See Figure
11.

Figure 11: Export wizard.

h. Click Next. In the Export Summary, confirm your selections, and then click Finish.
i. The Sales Revenue Generated by WLP Team PDF report will be displayed.

Congratulations! You have learned how to generate a tabular report in PDF.

Q1: Create a tabular report in HTML and PDF. The report displays the top five sales revenue generated in different
areas irrespective to any team. The areas with the highest sales revenue must be listed first. Provide the SQL
statement which is used to generate such report in your lab report. Your report should contain a table with the
following rows.

IV. Creating Chart


In this section, you will learn how to create a report which consists of charts. The Miniature table will be re-
used.

Page | 6 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
Imagine that you are to create a report which shows sales revenue generated by the three teams (i.e. MRMA,
RI, and WLP) in different areas. The details of each team are shown as a pie chart. In other words, the report
consists of three pie charts which each pie chart show the sales revenue breakdown according to areas for teams
MRMA, RI, and WLP respectively. The three pie charts are shown in Figure 12.

Figure 12: Pie charts show the sales revenue generated by different teams.

In order to generate such report, follow the steps below:


a. Click the Reports pane if it is visible. If it is not, select View > Reports. The Reports pane is
displayed.
b. In the Reports pane, right click User Defined Reports, and select New Report.
c. The Create Report dialog box displays Master Report properties. Connect to the LOCAL
schema and select the Advanced check box. The Master Report tree is displayed.
d. For the report name, enter Sales Revenue in Different Areas Generated by MRMA,
RI and WLP Teams. See Figure 13.
e. For the report style, select Chart. See Figure 13.
f. It is optional to enter the report description and tool tip.

Figure 13: Specifying report name and report style.

g. In Master Report, click SQL Query.


h. Enter the following SQL statement to generate the three pie charts.

SELECT TEAM, AREA, SUM(PRICE*QUANTITY) AS REVENUE FROM MINIATURE


GROUP BY TEAM, AREA;

i. Click Property. Select Pie Multiple for the chart type. See Figure 14.

Page | 7 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
Figure 14: Specifying chart type.

j. Click Plot Area. Check the Data Labels. Select Series Label and % Value for slice labels.
See Figure 15.

Figure 15: Specifying data labels.

k. Make sure the LOCAL schema is connected. Click Test Report and verify the output.
l. Click Apply to generate the report. When the report is exported as HTML. Your report should looks as
follows:

Page | 8 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)
Q2: Currently the company sells five products, namely: 0.9" Hulk, 0.8" Thor, 0.5" Captain America, 0.5" Iron Man
and 1.0" Black Widow. Create a chart report (horizontal bar chart) in HTML. The report displays the quantity of
each product sold in different areas. Provide the SQL statement which is used to generate such report in your lab
report. The following table shows the rows which are then represented as horizontal bar chart.

V. Lab Report Submission


Besides students name and matrix number, the lab report must contain the following:
solution for Q1 in Section III.
Solution for Q2 in Section IV.

Your report must be submitted to your respective teaching assistant, before the lab ends. Failure to submit the
lab report will be a disadvantage to you.

~~END OF LAB 04~~

Page | 9 CMT221/CMM222: Database Organization and Design (LAB 05)


S1-2017/2018 (LSY, NAA, TJS)

You might also like