Vous êtes sur la page 1sur 14

CHAPTER-4

SQL *REPORTWRITER
STRUCTURE 4.1 4.2 4.3 GETTING STARTED. SELECTIVE DUMP REPORT. MASTER-DETAIL REPORT. 4.3.1 4.3.2 4.4 4.5 Steps To Be Followed. Explanation

EXERCISE ANSWERS

4.1 GETTING STARTED Logging onto SQL*Report writer : To use SQL*ReportWriter, you will need a

usename and password for your Oracle database. At the $ prompt, key in sqlrep username/passwd TERM=ansixu Before you can get into SQL*ReportWriter, you must enter a valid Oracle username and password to ensure that Oracle recognizes your identity. After entering userid and password, screen 4.1 appears. Action Query Group Field Summary Text SQL*ReportWriter Report Parameter Help

Perform global operations on reports. Report Name : Screen 4.1 : SQL*ReportWriter opening screen. <Replace>

In screen 4.1, ( the opening screen ) the cursor is on the menu option Action. On selecting Action, a dropdown menu appears as displayed in screen 4.2. Action Query Group Field Summary Text SQL*ReportWriter Report Parameter Help

New Open Rename Drop Execute Generate Quit

Create a new report. Report Name : Screen 4.2 : The many choices in the Action option. Select the option New to create a new report. Enter a name for the report that you wish to create, say orders (screen 4.3). Action Query Group Field Summary Text SQL*ReportWriter Report Parameter Help <Replace>

New Open Rename Drop Execute Generate Quit

Name of New Report : orders

Enter a name for the new report Report Name : Screen 4.3 : Creating a new report. <Replace>

On striking <Enter>, the name of the report entered is displayed on the last line, against the heading Report Name as shown in screen 4.4. Action Query Group Field Summary Text SQL*ReportWriter Report Parameter Help

Perform global operations on reports. Report Name : orders <Replace>

Screen 4.4 : SQL ReportWriter screen, after naming a report. After naming the report, we have to inform SQL*ReportWriter of the tables that are to be used to extract data. The table and its column information can be passed to SQL*ReportWriter via the Query option. On selecting the Query option screen 4.5 is displayed. Action Query Group Field Summary Text Query Settings Report Parameter Help

Query Name : SELECT Statement

Query 1 of 1

Parent-Child Relationships Parent Query 1: Child Columns Parent 1 Columns Parent Query 2 : Parent 2 Columns

Enter a name for this query. Report Name : orders Screen 4.5 : Query option screen. <Replace>

The Cursor will be placed on the Query Name, where we are supposed to enter a name for each query (select statement) we write. We shall name it as Q_ord. We are creating a report to list all the orders from the ord table, ( ord table is describer in section 4.3) therefore write the select Statement as shown in screen 4.6. The naming convention used is Q_ for the query name. If only one table is being used, then the convention is Q_<Tablename>. Action Query Group Field Summary Text Query Settings Report Parameter Help

Query Name : Q_ord SELECT Statement Select * from ord Parent-Child Relationships Parent Query 1: Child Columns Parent 1 Columns

Query 1 of 1

Parent Query 2 : Parent 2 Columns

Enter a name for this query. Report Name : orders Screen 4.6 : Writing the SELECT statement. After keying in the select statement, accept it (by pressing the accept key sequence) and get back to SQL*ReportWriters opening screen (i.e. screen 4.1). Now select the Execute option to run the report. It is not necessary to select the Generate option before executing the report. The report will be automatically be generated once we select Execute. Before producing the actual report, a screen will be displayed with the default parameters as shown in screen 4.7. <Replace>

Parameter Values Parameter Destination Type File Name / Spool Device Printer Description File Number of Copies Value Screen orders.lis dflt 1 <Replace>

Enter the desired value for each parameter. Report Name : orders Screen 4.7 : Default report parameters

As we wish to look at the report on screen, we will accept the default settings displayed in screen 4.7, by selecting the accept key sequence. This will display the report on orders as shown below : Ordid Orderdate ------610 611 611 601 602 604 605 606 609 607 608 603 620 613 614 616 -----------07-JAN-87 11-JAN-87 15-JAN-87 01-MAY-86 05-JUN-86 15-JUN-86 14-JUL-86 14-JUL-86 01-AUG-86 18-JUL-86 25-JUL-86 05-JUN-86 12-MAR-87 01-FEB-87 01-FEB-87 03-FEB-87 Commplan ------------A B C A B A A A B C C Custid -------101 102 104 106 102 106 106 100 100 104 104 102 100 108 102 103 Shipdate ---------------08-JAN-87 11-JAN-87 20-JAN-87 30-MAY-86 20-JUN-86 30-JUN-86 30-JUL-86 30-JUL-86 15-AUG-86 18-JUL-86 25-JUL-86 05-JUN-86 12-MAR-87 01-FEB-87 05-FEB-87 10-FEB-87 Total ------------101.4 45 5860 2.4 56 698 8324 3.4 97.5 5.6 35.2 224 4450 6400 23940 764

The layout gives you all the particulars of an order at a glance. Well not exactly! There may be more orders than what are displayed on the first screen of the report. So if the records exceed the maximum display limit, then one has to have a way looking at the remaining records. To view the next page, press the next page key sequence. To view the previous page, press the previous page key sequence. Pressing either of these keys doesnt really help us to scroll down to see the remaining lines on the same page. To scroll, you need to release your cursor. This can be done by using the window key sequence. You can then use the up arrow or down arrow key to move up or down on the same page. 4.2 SELECTIVE DUMP REPORT The only change required for a selective dump report will be in the query that we write. Make the following change in the Query screen as shown in screen 4.8. Action Query Group Field Summary Text Query Settings Report Parameter Help

Query Name : Q_ord SELECT Statement Select * from ord where custid = 106 Parent-Child Relationships Parent Query 1: Child Columns Parent 1 Columns

Query 1 of 1

Parent Query 2 : Parent 2 Columns

Enter a name for this query. Report Name : orders Screen 4.8 : Selective dump query. <Replace>

Accept the Query and Execute the report. The following report will be generated. Ordid ------601 604 605 Orderdate Commplan -----------01-MAY-86 15-JUN-86 14-JUL-86 ------------A A A Custid 106 106 106 Shipdate 30-MAY-86 30-JUN-86 30-JUL-86 Total ------2.4 698 8324

-------- -----------

4.3

MASTER-DETAIL REPORT Generating a report with a Master/Detail relationship (i.e. extracting data from multiple

tables) involves more than one query. The concept will be made clear with an example. We shall create a new report with the name ord_details. The tables (alongwith their fields) involved in this Master/Detail relation are follows : Ord (Master) ordid orderdate commplan custid shipdate total item (Detail) ordid itemid prodid actualprice qty itemtot

4.3.1 STEPS TO BE FOLLOWED

1. Log in to SQL*ReportWriter in the normal manner. You will get the opening menu screen of SQL*ReportWriter (i.e. screen 4.1) 2. Select the Action option by pressing <Enter> key. From the dropdown menu that appears (i.e. screen 4.2), select New to create a new report. 3. Enter the report name (i.e. screen 4.3) as ord_details and accept it. 4. Next select the Query option, and screen 4.9 appears where we will write the first query. 5. Name the query Q_ord and write the select statement as shown in screen 4.9. This is the query for the data from the master table. 6. After writing the first query, press the key sequence for inserting a record below, so that we can specify the second query for selecting the data from the detail table. Screen 4.10 appears. It is the same query screen except for the query number which will be 2 of 2 instead of 1 of 1.

Action

Query Group

Field

Summary Text Query Settings

Report

Parameter

Help

Query Name : Q_ord SELECT Statement Select * from ord Parent-Child Relationships Parent Query 1: Child Columns Parent 1 Columns

Query 1 of 1

Parent Query 2 : Parent 2 Columns

Enter a name for this query. Report Name : ord_details Screen 4.9 : Writing the first query. <Replace>

Action

Query Group

Field

Summary Text Query Settings

Report

Parameter

Help

Query Name : Q_item SELECT Statement Select * from ord Parent-Child Relationships Parent Query 1: Q_ord Child Columns ordid Enter a name for this query. Report Name : ord_details Screen 4.10 : Writing the second query. Parent 1 Columns ordid

Query 2 of 2

Parent Query 2 : Parent 2 Columns

<Replace>

7. Name this query as Q_item and write the select statement as shown in Screen 4.10. This is the query to pick the data from the detail table.
4.3.2 EXPLANATION :-

Parent Query 1 :

Use this attribute to specify a query to be the parent of the query

displayed on screen. Choose a parent query from the list of values, which shows a list of names of potential parent queries. Child Columns : This, alongwith Parent 1 Columns and Parent 2 Columns allow you

to link together the data in two or more queries. When Parent Query 1 (and Parent Query 2) and pairs of matching columns are specified. SQL*ReportWriter will retrieve only the rows in the child that match the rows in the parent(s). The child query will be re-executed for each new row retrieved by the parent query. Use the list of values to enter columns to be matched with coumns from Parent Query 1 or Parent Query 2.

Parent 1 Columns : Allow you to link together the data from two or more queries. Parent 1 Columns are the columns from Parent Query 1. SQL*ReportWriter will retrieve only the rows in the child query that match the rows in the parent(s) column. The child query will be re-executed for each new row retrieved by the parent query. Use the list of values to enter columns to be matched with columns from the child query. After completing the above steps, press the accept key sequence so that you get back to opening menu. Select the Group option to change the alignment of G_item with respect to G_ord which will be right aligned, by default. Screen 4.11 will come up. By scrolling to the right, the Relative Position column will be visible as in screen 4.12. Make the necessary change in this column. Action Query Group Field Summary Text Group Settings Report Parameter Help

Group Name G_ord G_item

Query Q_ord Q_item

Parent Direction Down Down

Matrix Group

Page Break

> Enter the name of the query this group is associated with. Report Name : ord_details Screen 4.11 : Group settings. <List><Replace>

Action

Query Group

Field Summary Text Group Settings Lines Before

Report

Parameter

Help

Group Name G_ord G_item

Relative Position Below

Spaces Before

Spacing Record Feild 2

Fields Across

< Choose the position of this group in relation to the previous group. Report Name : ord_details Screen 4.12 : Group settings. Accept and Execute with the default parameters to test run the report. The output will be as follows : Ordid ------610 Ordid ------610 610 610 611 Ordid ------611 604 Orderdate -------------07-JAN-87 Itemid --------1 2 3 11-JAN-87 Itemid --------1 15-JUN-86 Commplan ------------A Prodid -------100860 100870 100890 B Prodid -------100861 A Custid -------101 Actualprice -------------35 2.8 58 102 Actualprice -------------45 Shipdate ---------08-JAN-87 Qty ------1 3 1 11-JAN-87 Qty ----1 Total ------101.4 Itemtot --------35 8.4 58 45 Itemtot ---------45 698 <List><Replace>

106 30-JUN-86

Ordid -------604 604 604 605 Ordid ------605 605 605 605 605 605

Itemid -------1 2 3 14-JUL-86 Itemid -------1 2 3 4 5 6

Prodid -------100890 100861 100860 A Prodid --------100861 100870 100890 100860 100863 102130

Actualprice -------------58 42 44 106 -------------45 2.8 58 24 9 3.4

Qty ------3 2 10 30-JUL-86 Qty --------100 500 5 50 100 10

Itemtot ---------174 84 440 8324 Itemtot --------4500 1400 290 1200 900 34

Actualprice

REFERENCES:1. ORACLE 2. ORACLE 7 - Oracle press book. - Ivan Bayross.

4.4

EXERCISES
A. FILL IN THE BLANKS

1. 2. 3. 4. 5. 6. 7.

To log on to SQL*Reportwriter, At the $ prompt, we need to type ____________. Before executing a report, we need to use ___________ option of Action drop down menu. To run the report, we need to select the _________ option of Action drop down menu. The Table and its Column information can be passed to SQL*Reportwriter via the __________ option. Generating a Report with a Master/detail relationship involves more than one ___________. ____________ and ____________ allows you to link together the data from two or more queries. The child query will be re-executed for each new row retrieved by the _________.

B. ANSWER THE FOLLOWING

1. Mention the different options that appears on SQL*Reportwriter screen. 2. Mention the different options that will appear in a Action drop down menu of SQL*Reportwriter screen. 3. Briefly specify the different steps that are to be followed to generate selective dump report.

C. PRACTICAL ASSIGNMENT

1. Generate a progress report of each students. Use STUDENT table which has following description. Name Reg-No Name date-of-birth year Data type Varchar2(6) Varchar2(25) Date Number(1)

2. For the table STUDENT described in previous assignment, generate a progress report for only second year students. 4.5 ANSWERS A. 1. SQL rep username/password TERM = ansixu. 2. Generate. 3. Execute. 4. Query. 5. Query. 6. Parent Columns 8. Parent Query. ==================== ****** ====================

Vous aimerez peut-être aussi