Friday, 27 October 2017

Parent Child Report - SQL Developer


  1. To create a parent child report in SQL Developer Click on the View Menu and then Reports.


  2. Once reports is shown right click on User Defined Reports and select New





  3. Give the report a name and in the SQL box enter the sql for the parent report.




  4. Click Apply


  5. Go Back to reports and edit the report.








  6. Click on child reports and enter a name for the child report.






  7. On the tree on the left hand side, expand child reports and click on SQL Query.

  8. Enter the query for the child report.
    In this report the child report ties to the parent report via the deptno number.
    The deptno number of the parent report is referenced by :DEPTNO. The bind variable must be in upper case and must be prefixed with a colon.



  9. Save the report.


  10. Double click the report in the reports tree to run it.  When an entry in the parent report is selected the appropriate children in the child report are shown.





Saturday, 21 October 2017

Drill Down Report - SQL Developer

In SQL Developer you can link one oracle report to another creating a drill down from the first report to the second. To do this we create two reports, the master report and the drill down report.

  1. First I'm going to create a master report based on the dept table.

  2. From the VIEW menu choose Reports.

    Once reports is displayed right click on User Defined Reports and select New Report





  3. The Create Report dialogue is displayed.

  4. Enter the query to select the details of the master report in the SQL section, in this case

      
    SELECT *
      FROM dept
    

    and click apply




    The newly created Dept report now appears under User Defined Reports.

  5. Right click on the report and run it.






  6. Next I'll create the drill down report.  This report is based on the emp table which details employees.  Each employee in this table belongs to a department shown in the Dept report above.

  7. As before I'll click on User Defined Reports and choose new report.

    I'll give it a name of emp and under SQL Query I'll enter

      
    SELECT *
      FROM emp
     WHERE deptno = :DEPTNO
    

    The where clause ties the drill down to the master report.  It says select records from emp where the deptno, (department number), equals the :DEPTNO bind value passed in.  When referencing a bind value it is always in upper case and always prefixed with a colon.





  8. Next I need to go back to the master report (dept).

  9. Edit the report and choose Drill Down.
    Click Add Report.
    Give the report a name and then under report click the drop down box and select the emp report.



  10. Save the report and then run it again.

  11. Right click on any department.  The employess report is shown in the menu.




  12. Click on employess and the employees report will be run for the selected deptartment