+ All Categories
Home > Documents > Building Reports with Oracle SQL Developer

Building Reports with Oracle SQL Developer

Date post: 28-Apr-2015
Category:
Upload: lewis-cunningham
View: 1,146 times
Download: 1 times
Share this document with a friend
Description:
IOUG 2007 Presentation
14
Insert focus area name here 1 Paper 474 BUILDING REPORTS WITH ORACLE SQL DEVELOPER Lewis R Cunningham, PricewaterhouseCoopers INTRODUCTION This paper, and the accompanying presentation, are written in association with the article, Making the Most of Oracle SQL Developer Reports, http://www.oracle.com/technology/pub/articles/cunningham-sqldev.html that I wrote for OTN in 2006. That paper was based on SQL Developer 1.0 and provided descriptions about most of the supplied reports in addition to providing examples of user defined reports. Besides explaining how to create both simple and complex user reports, a large portion of that paper revolved around manually configuring drill down reports and bind variables. SQL Developer 1.1 has added tons of new functionality in all areas of the tool but today I want to talk about the new reporting features. Oracle has made defining drill downs and bind variables much easier in addition to adding highly useful features such as parent-child reports and graphic charts. Today's presentation will discuss the new, and newly enhanced, features. This paper will use the HR sample schema available with any recent Oracle database. My examples and screen shots will be using Oracle 10g Express Edition. GETTING AND USING ORACLE SQL DEVELOPER Installing, configuring, and creating a connection to your database is a fairly simple affair but is beyond the scope of this paper. For details on these topics, see the Oracle SQL Developer Homepage, http://www.oracle.com/technology/products/database/sql_developer/index.html , on OTN. Once you have installed the product and have connected to the database, you can select the reports tab at the top of the navigator pane (Figure 1). Figure 1 - Oracle SQL Developer Reports Tab As the original paper is available on OTN, I will not rehash everything said in that paper. Instead, I will try to concentrate on the new features. SETTING UP FOLDERS In my original article, I made some points about using folders within the tool: Now you’ll create a simple report to get your feet wet. Log in as HR@XE. Click the last node in the navigator, User Defined Reports. Right-click the expanded node, and you’ll see a context menu with a list of options: Add Folder, Add Report, Delete, Copy, Cut, and Paste. Oracle SQL Developer maintains a tree structure for navigation; I suggest that you do the same as a best practice. Use folders to logically group your reports. You may choose to group them by application, which is what I do with my reports under the Employee Reports and the User Data
Transcript
Page 1: Building Reports with Oracle SQL Developer

Insert focus area name here

1 Paper 474

BBUUIILLDDIINNGG RREEPPOORRTTSS WWIITTHH OORRAACCLLEE SSQQLL DDEEVVEELLOOPPEERR

Lewis R Cunningham, PricewaterhouseCoopers

INTRODUCTION

This paper, and the accompanying presentation, are written in association with the article, Making the Most of Oracle SQL Developer Reports, http://www.oracle.com/technology/pub/articles/cunningham-sqldev.html that I wrote for OTN in 2006.

That paper was based on SQL Developer 1.0 and provided descriptions about most of the supplied reports in addition to providing examples of user defined reports. Besides explaining how to create both simple and complex user reports, a large portion of that paper revolved around manually configuring drill down reports and bind variables.

SQL Developer 1.1 has added tons of new functionality in all areas of the tool but today I want to talk about the new reporting features. Oracle has made defining drill downs and bind variables much easier in addition to adding highly useful features such as parent-child reports and graphic charts. Today's presentation will discuss the new, and newly enhanced, features.

This paper will use the HR sample schema available with any recent Oracle database. My examples and screen shots will be using Oracle 10g Express Edition.

GETTING AND USING ORACLE SQL DEVELOPER

Installing, configuring, and creating a connection to your database is a fairly simple affair but is beyond the scope of this paper. For details on these topics, see the Oracle SQL Developer Homepage, http://www.oracle.com/technology/products/database/sql_developer/index.html , on OTN.

Once you have installed the product and have connected to the database, you can select the reports tab at the top of the navigator pane (Figure 1).

Figure 1 - Oracle SQL Developer Reports Tab

As the original paper is available on OTN, I will not rehash everything said in that paper. Instead, I will try to concentrate on the new features.

SETTING UP FOLDERS

In my original article, I made some points about using folders within the tool:

Now you’ll create a simple report to get your feet wet. Log in as HR@XE. Click the last node in the navigator, User Defined Reports. Right-click the expanded node, and you’ll see a context menu with a list of options: Add Folder, Add Report, Delete, Copy, Cut, and Paste.

Oracle SQL Developer maintains a tree structure for navigation; I suggest that you do the same as a best practice. Use folders to logically group your reports. You may choose to group them by application, which is what I do with my reports under the Employee Reports and the User Data

Page 2: Building Reports with Oracle SQL Developer

Insert focus area name here

2 Paper 474

Dictionary applications shown in Figure 2 below. You might want to group your reports by some other criterion besides application name, but I would recommend against dumping everything under User Defined Reports.

Select Add Folder to create a new folder. For now, let’s call this folder Employee Reports. Enter anything you would like as a description. The ToolTip text will be displayed if you hover your mouse over that item in the navigator. Click Apply to save.

Figure 2 - Employee Reports Folder

Most of the actions taken within SQL Developer are done with a right click. For example, in Figure 3, I use a right click to view the reports context menu:

Figure 3 - Right Click Menu

When I say to right click and select an option, I mean from a menu such as the one in figure 2.

CREATING A SIMPLE REPORT

Every report starts with a query. The first report I will create is the Employee Listing that has been the staple of examples since the days when dinosaurs roamed accounting departments worldwide. In Figure 3, I entered some descriptive text and the query, SELECT * FROM employee.

Page 3: Building Reports with Oracle SQL Developer

Insert focus area name here

3 Paper 474

Figure 4 - Simple Report

The first thing that I would suggest noticing is the Test button. This will validate your query without you have to save and exit this form. When you press Test, you get a popup with a subset of data. If your query is invalid, you will see the error and can fix it. Figure 5 shows the Test window for this query.

Figure 5 - Report Query Test

Another button on this form to notice is the Load button. Load allows you to load a query from a text file. Pressing that button open a regular file open dialog where you can browse around and find your query file.

If we select Apply, it will save the report. Right click on the newly created report in the Employee Reports directory, and select Open. You may need to choose a selection from the connection select dialog. Figure 6 shows what your report should look like.

Page 4: Building Reports with Oracle SQL Developer

Insert focus area name here

4 Paper 474

Figure 6 - Simple Listing Output

When you are viewing the output, you have a right click menu that will allow you change your view or to export the data. Figure 7 shows the options.

Figure 7 - Output Context Menu

The Single Record View, Figure 8, shows the data in a vertical format.

Page 5: Building Reports with Oracle SQL Developer

Insert focus area name here

5 Paper 474

Figure 8 - Single Record View

Speaking of view the report vertically, ….

ALTERING REPORT FEATURES

While you may occasionally find a report that simple, the majority of reports that I have written are substantially more complex. As soon as you have a nice listing like this, some one will want the layout changed.

If you right click on the report and select Edit, you will be returned to the Create Report Dialog. Select the Table Details tab at the bottom of the dialog. Change the Table Type from Horizontal to Vertical (Figure 7).

Figure 9 - Table Type Dialog

I don't know why I find this simple feature so neat but it is one of my favorites in the reporting features of SQL Developer. If we run the report now, it looks like Figure 8.

Page 6: Building Reports with Oracle SQL Developer

Insert focus area name here

6 Paper 474

Figure 10 - Vertical Report Output

This particular report is more useful as a horizontal report but if you apply this feature to a column listing, it makes a lot sense. The fact that it is so easy to implement is awesome.

ADDING BIND VARIABLES

Adding a bind variable to a report in SQL Developer 1.1 is leaps and bounds easier than doing so in 1.0. It is a two-step process but is extremely easy to do. The first step is to modify your query as in Figure 11.

Figure 11 - Adding a bind to a query

Page 7: Building Reports with Oracle SQL Developer

Insert focus area name here

7 Paper 474

What I did here was add a bind variable to the query using the standard colon (:) syntax. In this case, I will want to see only those employees limited to a specific department id. In addition to modifying the query, I also need to define the bind variable in the Binds tab so that I will have a useful prompt and optionally a default value and tool tip. In figure 12, that is what I am defining.

Figure 12 - Add a Bind Prompt

I left the default null so that if I don't enter a value at run time, I will see all employees. Now when we run the report, we get a dialog asking us to enter a value for DEPT_ID (as in figure 13).

Figure 13 - Enter Bind Value Dialog

COMPLEX REPORTS

PARENT-CHILD REPORTS

One new feature in version 1.1 that I have been waiting for are parent child reports. It's a lot like a drill down report but is a lot more useful and automated. For example, we can modify our Employee Listing to display the employee's job history. In Figure 14, I add a child query to the main query. To do that, just hit the Add Child button on the Create Report Dialog.

Page 8: Building Reports with Oracle SQL Developer

Insert focus area name here

8 Paper 474

Figure 14 - Define Child Report

Notice that the original query did not need to change. The child query is defined with a bind variable, EMPLOYEE_ID (upper case required). SQL Developer knows that the EMPLOYEE_ID I am looking for is going to come from the parent query.

Figure 15 shows the output. When you click on a row that has history in the employee history table, it automatically populates the lower, child pane.

Page 9: Building Reports with Oracle SQL Developer

Insert focus area name here

9 Paper 474

Figure 15 - Parent-Child Report Output

If you add a second child report, it will show as a second tab in the lower pane. In figure 16, I define a child report that will display job information.

Figure 16 - Second Child Definition

Page 10: Building Reports with Oracle SQL Developer

Insert focus area name here

10 Paper 474

You can see the output on a second tab called, oddly enough, Job Information (Figure 17).

Figure 17 - Multiple Child Report Output

GRAPHIC CHART REPORTS

Creating a Chart is as easy as a table type report. If I continue with our ongoing example, I can add a third child report and create it as a pie chart (or bar chart but I like pie). Unlike a table type report, creating the chart is a three-step process.

Edit the report definition and choose Add Child. Figure 18 shows the definition of the chart query. In this query, I want to a pie chart of the salaries of everyone in the department.

Page 11: Building Reports with Oracle SQL Developer

Insert focus area name here

11 Paper 474

Figure 18 - Chart Definition

Notice that the report Style is Chart for this one.

A chart report needs three columns: x (dept) and y (employee) coordinates, and the value being measured (salary). All charts will work basically the same way.

The second step is to configure the chart itself. On a chart type report, there is an additional tab called Chart Details beneath the query. In Figure 19, I configure the chart as a 3d pie chart.

Page 12: Building Reports with Oracle SQL Developer

Insert focus area name here

12 Paper 474

Figure 19 - Chart Definition Details

The important drop down here is the Chart Type. You can play with the other options to see how they change the display. When I save this report and run it, I get the output in Figure 20.

Figure 20 - Chart Output

How awesome is that!

Page 13: Building Reports with Oracle SQL Developer

Insert focus area name here

13 Paper 474

REPORT REFRESH

You may have noticed the Refresh option on the report output (Figure 21).

Figure 21 - Report Refresh

You can select an interval of time that will tell SQL Developer to automatically refresh the report for you. This is useful when monitoring system statistics that change over time.

DBMS_OUTPUT AND PL/SQL REPORTING

You can easily create a report using PL/SQL and DBMS_OUTPUT by choosing the plsql-dbms_output report type. I have found that straight dbms_output.put_line will not format the output correctly so I use the HTML tag <p> to format rows. You can get a lot fancier by including additional HTML tags. I heartily recommend that you play with it and see how powerful it is. Figure 22 shows the definition for a very simple report that lists every employee's name.

Figure 22 - PL/SQL Report Definition

Figure 23 shows what the report output looks like.

Page 14: Building Reports with Oracle SQL Developer

Insert focus area name here

14 Paper 474

Figure 23 - PL/SQL Report Output

CONCLUSION

This paper does not show all of the features of SQL Developer reporting. If you use this paper in conjunction with my paper from last year, Making the Most of Oracle SQL Developer Reports, http://www.oracle.com/technology/pub/articles/cunningham-sqldev.html you will be familiar with most of the features that SQL Developer gives you.

SQL Developer Version 1.1 is practically a new product. The number of new features is dramatic. If you haven't yet tried SQL Developer, I recommend that you do. You may not use it for all of your needs, but as a free tool that comes with the database, it's hard to go wrong.


Recommended