Create a Layout Oracle Fusion Middleware Online Documentation Library

Building a Paper Report with REF CURSORs 41-13 start_date, end_date, job_id, department_id from job_history where :department_id=department_id; return tempcv_container; end; END;

6. Click Compile.

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

8. Click Close.

9. Now that the function is defined, you must add it to the package spec so that it can be referenced. Other program units will know about the function in the package body only if it is described in the package spec.

10. In the Object Navigator, double-click the CONT_CV Package Spec object to

display the PLSQL Editor. 11. In the PLSQL Editor, type the following line above the END; statement: function query_container p_department_id number return container_refcur;

12. Click Close.

13. Choose Program Compile All.

14. Click OK when done.

15. In the Object Navigator, under the Program Units node, double-click Q_

CONTAINERREFCURDS to display the PLSQL Editor. 16. In the PLSQL Editor, edit the code to look as follows: function Q_containerRefCurDS return cont_cv.container_refcur is temp_container cont_cv.container_refcur; begin temp_container:=cont_cv.query_container :department_id; return temp_container; end; When you are done, all of the querys logic will reside in the function named query_container. From now on, when you change query_container, you will change this and any other queries that reference it.

17. Click Compile.

Note: You can open the provided file refcursor_code.txt to copy and paste the code into Reports Builder. Note: You can open the provided file refcursor_code.txt to copy and paste the code into Reports Builder. 41-14 Oracle Reports Users Guide to Building Reports 18. If any compilation errors occur, check the code for syntax errors and recompile as needed.

19. Click Close.

20. Click the Paper Design button in the toolbar to view the report in the Paper Design view. 21. Save the report as ref_67_your_initials.rdf. Optional Exercise: Repeat the above steps for the other two queries in the report.

41.9 Move the Packages Into a Library

If you have many reports that use these same REF CURSOR types and SELECT statements, you can move the program units that you created into a PLSQL library stored in a file, so that other reports can easily share the code. The steps in this section will help you to move the program units to a PLSQL library. To move the packages into a library: 1. In the Object Navigator, click the PLSQL Libraries node, then click the Create button in the toolbar to add a new library.

2. Choose File Save As.

3. Type DEPT_CONTAINER as the Library.

4. Ensure that File System is selected.

5. Click OK.

6. Drag and drop the following program units from your report to the Program

Units node under the newly created DEPT_CONTAINER library: ■ CONCL_CV Package Spec ■ CONT_CV Package Spec ■ CONT_CV Package Body ■ PORT_CV Package Spec 7. Save DEPT_CONTAINER. 8. If the Paper Design view is open, close it.

9. In the Object Navigator, under the Program Units node for your report, delete

CONCL_CV Package Spec, CONT_CV Package Spec, CONT_CV Package Body, and PORT_CV Package Spec.

10. Click the Attached Libraries node for your report, then click the Create button in

the toolbar to add a new attached library.

11. Click Browse to find the DEPT_CONTAINER library. It will have a .PLL file

extension. After you have found and selected DEPT_CONTAINER, click Open. 12. Click Attach. Note: If the Paper Design view is open when you delete the packages from the report, you may get some errors. Building a Paper Report with REF CURSORs 41-15

13. Choose Program Compile All.

14. Click OK to close the Compile window.

15. Click the Run Paper Layout button in the toolbar to run the report and view it in the Paper Design view. 16. Save the report as ref_68_your_initials.rdf.

41.10 Summary

Congratulations You have finished the REF CURSOR query sample report. You now know how to: ■ create package specs that define REF CURSORs. ■ create REF CURSOR queries. ■ create data links between REF CURSOR queries. ■ create summaries to describe data. ■ create a report layout. ■ move SELECT statements into packages. ■ move packages into a PLSQL library. For more information on any of the wizards, views, or properties used in this example, refer to the Oracle Reports online Help, which is available in Oracle Reports Builder or hosted on the Oracle Technology Network OTN, as described in Section 4.1.1, Using the Oracle Reports online Help .