Create a REF CURSOR Query

41-8 Oracle Reports Users Guide to Building Reports ■ Under the General Information node, set the Name property to G_conlabel. 4. In the Data Model view, your data model should look similar to the following: Figure 41–5 Data model with group 5. Save the report as ref_63_yourinitials.rdf.

41.5 Create Links Between REF CURSOR Queries

Currently, the queries that you have created are unrelated. To create relationships between them, you need to create group-to-group data links. The steps in this section will help you create the links. To create links between REF CURSOR queries: 1. In the Data Model view, click the Data Link tool in the tool palette.

2. Click the title bar of G_DEPARTMENT_ID, and drag a link to the title bar of G_

EMPLOYEE_ID .

3. Double-click q_container to display the PLSQL Editor.

4. In the PLSQL Editor, append code to the WHERE clause of the SELECT statement

to specify which columns are being used as primary and foreign keys: After from job_history, add the following code: where :department_id = department_id; Be sure that the semicolon ; now follows the WHERE clause. Note that :department_id is a bind variable referring to the DEPARTMENT_ID in G_DEPARTMENT_ID.

5. Click Compile.

6. If any compilation errors occur, check the code for syntax errors and recompile as needed.

7. Click Close.

8. In the Data Model view, click the Data Link tool in the tool palette.

9. Click the title bar of G_EMPLOYEE_ID and drag a link to the title bar of G_

EMPLOYEE_ID1 . Note: You can open the provided file ref_emp63.rdf and display the Data Model to compare your results. Building a Paper Report with REF CURSORs 41-9

10. Double-click q_conclass to display the PLSQL Editor.

11. In the PLSQL Editor, add a WHERE clause to the SELECT statement: Insert your cursor between FROM EMPLOYEES and the semicolon ;, and press ENTER or RETURN to create a new line, then add the following code: where :employee_id = employee_id; Be sure that the semicolon ; now follows the WHERE clause. Note that :employee_id is a bind variable referring to the EMPLOYEE_ID column in G_EMPLOYEE_ID.

12. Click Compile.

13. If any compilation errors occur, check the code for syntax errors and recompile as needed.

14. Click Close.

15. Your data model should look similar to the following: Figure 41–6 Data model with links 16. Save the report as ref_64_your_initials.rdf.

41.6 Add Summary Columns

Now that your queries are complete and linked, the steps in this section will help you to create columns to summarize the data. To add summary columns: 1. In the Data Model view, click the Summary Column tool in the tool palette.

2. Click inside the G_EMPLOYEE_ID group to create a summary column.

3. Double-click the new summary column object CS_1 to display the Property

Inspector, and set the following properties: ■ Under General Information, set the Name property to CS_classcount. Note: You can open the provided file ref_emp64.rdf and display the Data Model to compare your results. 41-10 Oracle Reports Users Guide to Building Reports ■ Under Summary, set the Function property to Count, set the Source property to employee_id, and set the Reset At property to G_department_id. You have now created a summary that counts up the number of employees. You will not use the summary in this reports layout, but you will use it as the source for other, more interesting summaries later. 4. Repeat the steps above to create summaries with the following characteristics: You may not understand these summaries now. Their purpose will become clearer when you create the report layout and preview the live data. Your data model should look similar to the following: Figure 41–7 Data model with summary columns 5. Save the report as ref_65_your_initials.rdf.

41.7 Create a Layout

Now that you have a working data model, the steps in this section will help you to create a layout. To create a paper layout:

1. In the Object Navigator, right-click the report name and choose Report Wizard.

Table 41–2 Summary Characteristics Create in Group Name Function Source Reset At G_conlabel CS_conlabel_ classcount Sum CS_classcount G_conlabel G_ department_ id CS_port_count Sum CS_conlabel_ classcount G_ DEPARTMENT_ ID Note: You can also compare your results to the file we have provided, called ref_emp65.rdf.