advanced discoverer techniques
TRANSCRIPT
Advanced Discoverer Techniques
Contact: Ben Lamb
Phone: (03) 9879 4060
Email: [email protected]
Document Date: 15 February 2008
Advanced Discoverer Techniques
2
Table of Contents
1 Creating new folders in Discoverer Administrator ................................................. 4
1.1 Creating a new Business Area ................................................................................ 4
1.2 New folder on an existing database table ................................................................ 4
1.3 New Folder from a SQL Query ................................................................................ 6
2 Linking Worksheets ................................................................................................. 8
2.1 Create the worksheets to link .................................................................................. 8
2.2 Employee List ......................................................................................................... 8
2.2.1 Employee Details ............................................................................................. 9
2.3 Create the Link ....................................................................................................... 9
3 Creating Custom Joins in Administrator .............................................................. 13
3.1 Inner Joins ............................................................................................................ 13
3.2 Outer Joins ........................................................................................................... 14
3.2.1 Create Outer Joins in Administrator ............................................................... 14
4 Using PL/SQL functions for complex logic .......................................................... 16
4.1 Creating functions via Administrator ...................................................................... 16
4.1.1 Create the Function ....................................................................................... 16
4.1.2 Create Custom Folder from a SQL Query ...................................................... 17
4.2 Calling functions via Discoverer ............................................................................ 18
4.2.1 Create the Database Package ....................................................................... 18
4.2.2 Register the PL/SQL Function ....................................................................... 19
4.2.3 Create the calculation .................................................................................... 20
Advanced Discoverer Techniques
3
Introduction
Discoverer users are often unaware of advanced features Discoverer is capable of. Once you’ve been using Discoverer for a while, you may want to extend beyond the basics to add more complex logic, access additional information from your database or have more detailed reports.
This whitepaper outlines some steps on how to configure Discoverer to perform more complicated tasks.
Specifically, this paper will describe:
• Creating new Folders and joins in Administrator
• Registering PL/SQL functions in Administrator to be used as calculations in Discoverer
• Including PL/SQL packages to perform complex logic from your Discoverer report
• Creating smart workbooks to link worksheets
Advanced Discoverer Techniques
4
1 Creating new folders in Discoverer Administrator A folder can be either a link to an existing database table or a SQL query. They are usually created to produce a folder based from an existing database table that does not already exist in the EUL or to combine a number of database tables into a single folder.
Note: When creating new folders against a vendor supplied EUL, create a new Business Area for your new folders so that if the EUL changes because of an upgrade, your work will not be affected.
1.1 Creating a new Business Area To create a new Business Area log into Administrator and click on Insert->Business Area->New. You can change the name of the Business Area to suit what kind of folders it will contain or who will have access to it. In this example I will call it Navigo Custom.
1.2 New folder on an existing database table To create a new folder as an exact copy of an existing database table, click on the Business Area you want to add the folder to, click on Insert->Folder->From Database. From here you can find an existing database table and add it to your Business Area.
Advanced Discoverer Techniques
5
They are some options you can choose to do:
• Automatically create joins to other table
• Create date hierarchies
• Create a list of values (LOV)
You can also clean the column names up by choosing to replace underscores with spaces, remove column prefixes and capitalise the first character of the columns or all words. You can also sort the folder and items if you like.
Advanced Discoverer Techniques
6
And then the folder is created
1.3 New Folder from a SQL Query Frequent users of Discoverer will want to link the same folders together over and over. To save time, folders can be created that join the tables together in the background so users will be able to just choose a single folder that contains their data.
Advanced Discoverer Techniques
Example
If users only ever want to get details for employees whose job is based in Melbourne, a folder can be made that will only contain this information.
To create the folder, click on the Business Area you want to add the folder to and click Insert->Folder->Custom. This will bring up an area where you can enter the SQL for the custom folder.
To check the SQL query click Validate SQL and then OK and the folder is now created
Employee employee# name address
Job employee# start_date location
Melbourne_emps employee# name address start_date location
Turn Into
Advanced Discoverer Techniques
8
2 Linking Worksheets It is useful to be able to be able to link from one worksheet to another and pass parameters to the new worksheets from the original. This allows groups of reports to be used together without having to remember and type in parameters each time you load a new worksheet.
This can be done both between different worksheets in the same workbook or between worksheets in different workbooks.
2.1 Create the worksheets to link Two workbooks will be created
• Employee List – This will contain a list of employees showing their employee id, first name and last name
• Employee Details – this will contain employee information like email, phone number, salary, manager and department
2.2 Employee List Create a report with the following fields
• Employee id
• First Name
• Last Name
Advanced Discoverer Techniques
9
2.2.1 Employee Details Create a report with the following fields
• Employee id
• First Name
• Last Name
• Phone Number
• Salary
• Manager Id
• Department Id Create a parameter for employee Id
2.3 Create the Link Open the report Employee List and click anywhere in the Employee id field then click
Tools -> Manage Links
Click New Link and fill in the link name, where you want to link to, destination workbook and destination worksheet
Advanced Discoverer Techniques
10
Click on Parameters to pass a value to the parameter in the destination worksheet
Now the link is created
Advanced Discoverer Techniques
11
You’ll notice that the field Employee Id has little triangles next to each employee Id
By linking on the triangle a list of all links associated will appear
Advanced Discoverer Techniques
12
By clicking this link it will open up the linked workbook passing through the Employee Id as the parameter
You can have as many links as you need attached to any field in your report creating a quick and easy way to look at details from multiple sheets without having to open workbooks manually and enter parameters.
Advanced Discoverer Techniques
3 Creating Custom Joins in Administrator There are two types of joins used in Administrator:
• Inner Join
• Outer Join
The following two tables will be used as our sample data.
Which contain the data
3.1 Inner Joins
These are the most commonly used type of joins. They join a record in one folder to a record in another folder. If the record does not exist in one of the folders it will not be shown. Using the above folders an inner join would return the following results.
If there isn't a matching record in both tables the record will not be shown
Employee# Name Address Position#
1234 John Blogg 1 Bond St 123 1122 Matt Jones 7 Grand St 144 1313 Pete Mulder 2 Sunny St 121
Inner Join
Employee# Name Address
1234 John Blogg 1 Bond St 1357 Jane Smith 4 Devon St 1122 Matt Jones 7 Grand St 1313 Pete Mulder 2 Sunny St
Employee# Position#
1234 123 1122 144 154 1313 121
Employees Positions
Positions
employee# position#
Employees
employee# name address
Advanced Discoverer Techniques
3.2 Outer Joins Outer joins are not used as often but are very useful. If a record exists in one folder but not in the other folder they will still be shown. Using the above folders, an outer join would return the following results.
3.2.1 Create Outer Joins in Administrator Using employee and positions (defined above), an outer join can be created by clicking on the Positions folder and then clicking Insert->Join and choosing positions.employee# and employees.employee#
Employee# Name Address Position#
1234 John Blogg 1 Nelson St 123 1357 Jane Smith 4 Devon St 1122 Matt Jones 7 Grand St 144 154 1313 Pete Mulder 2 Sunny St 121
Outer Join
Advanced Discoverer Techniques
15
Click next and then click the radio button Outer join on detail then click finish
Once done, the joins can be seen when the folders are expanded
Advanced Discoverer Techniques
16
4 Using PL/SQL functions for complex logic Hard to create complex logic in Discoverer, you can use PL/SQL functions to overcome this limitation.
PL/SQL function can be called either from a SQL folder in Administrator or from a calculation in Discoverer.
• A SQL folder in Administrator would be used when all the PL/SQL needs to run can be found in the folders it links to.
• A calculation via Discoverer would be used when the PL/SQL needs data from Discoverer like user parameters.
4.1 Creating functions via Administrator Example
If employees have multiple jobs over the course of their career and you want to find their maximum base salary at any point in their career, this can be found through PL/SQL referenced through a SQL custom folder.
4.1.1 Create the Function PL/SQL called custom_packages.get_max_base_salary must be created, which will take two parameters, employee_number and job_number. The PL/SQL will look through all occupancies and find the highest base salary the employee has ever received.
function get_max_base_salary
( pi_employee# in varchar2,
pi_job# in varchar2 )
return number is
v_max_base_salary number;
cursor c_get_max_base_salary is
select max(o.base_salary)
from occupancy o
where o.employee# = pi_employee#
and o.job# = pi_job#;
begin
open c_get_max_base_salary;
fetch c_get_max_base_salary into v_max_base_salary;
close c_get_max_base_salary;
return v_max_base_salary;
end;
Advanced Discoverer Techniques
17
4.1.2 Create Custom Folder from a SQL Query SQL queries have the ability to call the PL/SQL, so create a custom SQL folder that will get any information you need and also call the database package. Assuming there is a folder called OCCUPANCY that has the following fields, employee_number, job_number and base_salary we can create the following:
Click on the business area you want to add the new folder to and click insert->folder->custom. This will bring up an area to create a custom folder. Next, type the following SQL
Once you click OK you will have a new folder that will return the maximum base salary for
each employee.
Advanced Discoverer Techniques
18
4.2 Calling functions via Discoverer Functions that are linked to Administrator will work well in most situations, however parameters cannot be passed to the function from Discoverer. It can be useful to pass parameters from Discoverer if you need to base your results on a user defined parameter.
Example
If you want to find employees base salary based on a particular date, this may prove difficult if an employee has one occupancy but their salary, which is based of their award/classification, changes often throughout the occupancy. Discoverer can allow a calculation to be called that will reference the function passing it parameters.
4.2.1 Create the Database Package Create the package called custom_package.get_base_salary_at_date which will take three parameters, award, classification and as_at_date. The database package will look up the employees salary based on the award/classification at the date you pass to it.
function get_max_base_salary_at_date
( pi_award in varchar2,
pi_classification in varchar2,
pi_as_at_date in date )
return number is
v_max_base_salary number;
cursor c_get_max_base_salary_at_date is
select max(a.salary)
from award_class a
where a.award = pi_award
and a.classification = pi_classification
and a.start_date = ( select max(a1.start_date)
from award_class a1
where a1.award = a.award
and a1.classification = a.classification
and a1.start_date <= pi_as_at_date
and a1.end_date >= pi_as_at_date );
begin
open c_get_max_base_salary_at_date;
fetch c_get_max_base_salary_at_date into v_max_base_salary;
close c_get_max_base_salary_at_date;
return v_max_base_salary;
end;
Advanced Discoverer Techniques
19
4.2.2 Register the PL/SQL Function The PL/SQL must be registered through Administrator in order for it to be called from Discoverer. To do this go to Tools->Register PL/SQL Functions. From here we can import
the created PL/SQL by clicking the import button and finding the created PL/SQL.
Click Validate to make sure the PL/SQL is valid and then click OK. Now you will be able to reference the PL/SQL from Discoverer.
Note: You must reconnect to any existing Discoverer connections to be able to use the package.
Advanced Discoverer Techniques
20
4.2.3 Create the calculation Next create a calculation through Discoverer that will call the PL/SQL. The calculation will have the following in it:
(:as_at_date in this example is a user defined parameter)
This will allow reports to be made through Discoverer that use complicated calculations based on parameters that could not be done solely through Discoverer.