Building Reports With Oracle SQL Developer
Building Reports With Oracle SQL Developer
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.
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 youll 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 youll 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
1 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, lets 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.
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:
When I say to right click and select an option, I mean from a menu such as the one in figure 2.
Paper 474
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.
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.
Paper 474
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.
The Single Record View, Figure 8, shows the data in a vertical format.
Paper 474
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.
Paper 474
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.
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.
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).
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.
Paper 474
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.
Paper 474
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.
You can see the output on a second tab called, oddly enough, Job Information (Figure 17).
10
Paper 474
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.
11
Paper 474
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.
REPORT REFRESH
You may have noticed the Refresh option on the report output (Figure 21).
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.
13
Paper 474
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.
14
Paper 474