chapter 9 : sql*plus reports

57
Bordoloi and Bordoloi and Bock Bock Chapter 9 : Chapter 9 : SQL*PLUS SQL*PLUS REPORTS REPORTS

Upload: parry

Post on 13-Jan-2016

34 views

Category:

Documents


1 download

DESCRIPTION

Chapter 9 : SQL*PLUS REPORTS. A SQL*Plus PROGRAM COMMAND File. Interactive commands can be used to specify report headings, report footers, report titles, page numbers, and other common report features that managers tend to request. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Chapter 9 : Chapter 9 : SQL*PLUS REPORTSSQL*PLUS REPORTS

Page 2: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

A SQL*Plus PROGRAM COMMAND FileA SQL*Plus PROGRAM COMMAND File

• Interactive commands can be used to specify report Interactive commands can be used to specify report headings, report footers, report titles, page headings, report footers, report titles, page numbers, and other common report features that numbers, and other common report features that managers tend to request.managers tend to request.

• Unfortunately, if you exit SQL*Plus, all of the Unfortunately, if you exit SQL*Plus, all of the information about a report's features is lost unless information about a report's features is lost unless you save your commands in a file.you save your commands in a file.

• For this reason, we will also focus on creating files For this reason, we will also focus on creating files that will store SQL*Plus commands. We'll refer to that will store SQL*Plus commands. We'll refer to this type of file as a SQL*Plus program command this type of file as a SQL*Plus program command file, or simply a SQL program. The filename file, or simply a SQL program. The filename extension used for these files is extension used for these files is .sql.sql. .

Page 3: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

ExampleExample

• Following program gives a sample SQL*Plus Following program gives a sample SQL*Plus program command file.program command file.

• This SQL program will produce the report shown in This SQL program will produce the report shown in Figures 9.1a and 9.1b. All of the data for the report Figures 9.1a and 9.1b. All of the data for the report is selected from the is selected from the assignmentassignment table of the table of the Company database. Company database.

• The SQL program has numerous commands. The SQL program has numerous commands.

Page 4: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

ExampleExample

REM Program: ch9-1.sqlREM Program: ch9-1.sqlREM Programmer: dbock; 3-20-2003REM Programmer: dbock; 3-20-2003REM Description: A program to list employee work REM Description: A program to list employee work

history history REM on projects.REM on projects.  TTITLE 'Project Information' TTITLE 'Project Information' BTITLE SKIP 1 CENTER 'Not for external dissemination.' BTITLE SKIP 1 CENTER 'Not for external dissemination.' REPHEADER 'Project Report #1 –- prepared by D. Bock' REPHEADER 'Project Report #1 –- prepared by D. Bock'

SKIP 2SKIP 2REPFOOTER SKIP 3 '-- Last Page of Report --'REPFOOTER SKIP 3 '-- Last Page of Report --'  SET LINESIZE 55SET LINESIZE 55SET PAGESIZE 24SET PAGESIZE 24SET NEWPAGE 1SET NEWPAGE 1  

Page 5: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Example Cont’dExample Cont’d

COLUMN "Emp. Soc. Sec. #" FORMAT A16COLUMN "Emp. Soc. Sec. #" FORMAT A16COLUMN "Hours Worked" FORMAT 999.99COLUMN "Hours Worked" FORMAT 999.99SELECT work_emp_ssn "Emp. Soc. Sec. #",SELECT work_emp_ssn "Emp. Soc. Sec. #", work_pro_number "Project #", work_hours "Hours work_pro_number "Project #", work_hours "Hours

Worked"Worked"FROM assignmentFROM assignmentORDER BY work_emp_ssn, work_pro_number;ORDER BY work_emp_ssn, work_pro_number;

• The report produced is shown next.The report produced is shown next.

Page 6: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Sun Apr 14 page 1Sun Apr 14 page 1 Project InformationProject Information  Project Report #1 - prepared by D. BockProject Report #1 - prepared by D. Bock  Emp. Soc. Sec. # Project # Hours WorkedEmp. Soc. Sec. # Project # Hours Worked---------------- ---------- ---------------------------- ---------- ------------999111111 1 31.40999111111 1 31.40999111111 2 8.50999111111 2 8.50999222222 10 34.50999222222 10 34.50999222222 30 5.10999222222 30 5.10999333333 3 42.10999333333 3 42.10999444444 1999444444 1999444444 2 12.20999444444 2 12.20999444444 3 10.50999444444 3 10.50999444444 10 10.10999444444 10 10.10999444444 20 11.80999444444 20 11.80999555555 20 14.80999555555 20 14.80999555555 30 19.20999555555 30 19.20999666666 20999666666 20999887777 10 10.20999887777 10 10.20   Not for external dissemination.Not for external dissemination.

Page 7: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Sun Apr 14 page 2Sun Apr 14 page 2 Project InformationProject Information  Emp. Soc. Sec. # Project # Hours WorkedEmp. Soc. Sec. # Project # Hours Worked---------------- ---------- ---------------------------- ---------- ------------999887777 30 30.80999887777 30 30.80999888888 1 21.00999888888 1 21.00999888888 2 22.00999888888 2 22.00      -- Last Page of Report ---- Last Page of Report --               Not for external dissemination.Not for external dissemination.

Page 8: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

RemarksRemarks

• Optional remarks are typically entered at the Optional remarks are typically entered at the beginning of a command file program that identify beginning of a command file program that identify the filename, programmer name, and date of the filename, programmer name, and date of program creation. program creation.

• A brief description of the program is also provided. A brief description of the program is also provided. You may also list modifications made by You may also list modifications made by programmer name, date and description here.programmer name, date and description here.

• Remarks and blank lines are used throughout a Remarks and blank lines are used throughout a program to enhance the understandability and program to enhance the understandability and readability of programming code.readability of programming code.

Page 9: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• Titles and footers on reports enhance the meaning Titles and footers on reports enhance the meaning of reports for managerial system users. of reports for managerial system users.

• Reports are rarely disseminated to managers Reports are rarely disseminated to managers without appropriate title and footers.without appropriate title and footers.

• SQL*Plus supports the programming of four types SQL*Plus supports the programming of four types of titles and footers:of titles and footers:

1.1. Top title,Top title,2.2. Bottom title,Bottom title,3.3. Report header andReport header and4.4. Report footer. Report footer.

Page 10: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• The TTITLE command (short for top title) prints a The TTITLE command (short for top title) prints a title on title on each pageeach page of a report. of a report.

• When a simple TTITLE command like the one When a simple TTITLE command like the one shown below is used, the report will automatically shown below is used, the report will automatically display the report date and page number. display the report date and page number.

TTITLE 'Project Information'TTITLE 'Project Information'

Page 11: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• You can also issue the TTITLE command You can also issue the TTITLE command interactively at the SQL> prompt. interactively at the SQL> prompt.

• The first TTITLE command shown below will turn The first TTITLE command shown below will turn the report title off. the report title off.

• The second one will change the report title The second one will change the report title interactively when followed by a slash (/) interactively when followed by a slash (/) command. command.

TTITLE OFFTTITLE OFFTTITLE 'Project and Employee TTITLE 'Project and Employee Information'Information'//

Page 12: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• The BTITLE command prints a bottom title with The BTITLE command prints a bottom title with the specified information at the bottom of the specified information at the bottom of each each pagepage of a report. of a report.

• For example, your organization may want each For example, your organization may want each page of a report marked as not for external page of a report marked as not for external dissemination as is shown in the BTITLE command dissemination as is shown in the BTITLE command here.here.

BTITLE SKIP 1 CENTER 'Not for external BTITLE SKIP 1 CENTER 'Not for external dissemination.' dissemination.'

  

Page 13: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• The SKIP clause is optional. The SKIP clause is optional. • SKIP 1 will insert one blank line into the report.SKIP 1 will insert one blank line into the report.• You can specify the number of lines to skip. If the You can specify the number of lines to skip. If the

SKIP option is specified prior to the bottom title, as SKIP option is specified prior to the bottom title, as is done above, then one line is skipped prior to is done above, then one line is skipped prior to printing the bottom title.printing the bottom title.

• The CENTER option centers the bottom title The CENTER option centers the bottom title output. output.

Page 14: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• In addition to CENTER, you can also use the In addition to CENTER, you can also use the keywords RIGHT and LEFT within both the keywords RIGHT and LEFT within both the TTITLE and BTITLE commands to control the TTITLE and BTITLE commands to control the display of report information. display of report information.

• An example multi-lined TTITLE command is An example multi-lined TTITLE command is shown below. shown below.

TTITLE LEFT date_var –TTITLE LEFT date_var – RIGHT 'Page: ' FORMAT 99 sql.pno SKIP 1 -RIGHT 'Page: ' FORMAT 99 sql.pno SKIP 1 - CENTER 'Project and Employee Information'CENTER 'Project and Employee Information'

Page 15: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Top and Bottom TitlesTop and Bottom Titles

• A dash ( - ) at the end of a line continues the A dash ( - ) at the end of a line continues the TTITLE command.TTITLE command.

• The The date_vardate_var entry is a variable name that stores entry is a variable name that stores the date.the date.

• When a complex TTITLE command is used, Oracle When a complex TTITLE command is used, Oracle does not automatically print the date and page does not automatically print the date and page number information as was done earliernumber information as was done earlier . .

Page 16: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Report Headers and FootersReport Headers and Footers

• A report header can be used to add meaningful A report header can be used to add meaningful information to the top of the information to the top of the first pagefirst page of a report. of a report.

• You should use the REPHEADER command You should use the REPHEADER command whenever you want information to be displayed on whenever you want information to be displayed on only the first page.only the first page.

• The REPHEADER command shown below uses the The REPHEADER command shown below uses the SKIP 2 option to insert two blank lines immediately SKIP 2 option to insert two blank lines immediately after the report header is printed. You'll also notice after the report header is printed. You'll also notice that the report header prints after the top title line.that the report header prints after the top title line.

REPHEADER 'Project Report #1 -- prepared by REPHEADER 'Project Report #1 -- prepared by D. Bock' SKIP 2D. Bock' SKIP 2

Page 17: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Report Headers and FootersReport Headers and Footers

• Report footers add meaningful information to the Report footers add meaningful information to the bottom of the bottom of the last pagelast page of a report. of a report.

• In the command shown here, the SKIP 3 option In the command shown here, the SKIP 3 option provides for three skipped blank lines prior to provides for three skipped blank lines prior to printing the report footer.printing the report footer.

• You will also note that the report footer prints prior You will also note that the report footer prints prior to the bottom title line. to the bottom title line. REPFOOTER SKIP 3 '-- Last Page of Report --'REPFOOTER SKIP 3 '-- Last Page of Report --'

• The OFF option also applies to report headers and The OFF option also applies to report headers and footers, and will turn the report header and/or footer footers, and will turn the report header and/or footer off.off.

Page 18: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Setting the Line and Page SizeSetting the Line and Page Size

• The SET LINESIZE command specifies the size of The SET LINESIZE command specifies the size of an output line in characters.an output line in characters.

• The example report shown before has a line size of The example report shown before has a line size of 55 characters.55 characters.

SET LINESIZE 55SET LINESIZE 55

• Similarly, the SET PAGESIZE command specifies Similarly, the SET PAGESIZE command specifies the number of lines to be printed per page. the number of lines to be printed per page.

• A typical setting is 50 to 55 lines of output per page A typical setting is 50 to 55 lines of output per page for 10-point or 12-point printer fonts.for 10-point or 12-point printer fonts.

• The command shown below sets the page size to 50 The command shown below sets the page size to 50 lines.lines.

SET PAGESIZE 50SET PAGESIZE 50

Page 19: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Setting the Line and Page SizeSetting the Line and Page Size

• The SET NEWPAGE command specifies the The SET NEWPAGE command specifies the number of blank lines to print before the top title number of blank lines to print before the top title line of a report, that is, the line that displays the line of a report, that is, the line that displays the report date and page number. report date and page number.

• This is useful for aligning reports produced by This is useful for aligning reports produced by various types of printers. various types of printers.

• The SET NEWPAGE command does not affect the The SET NEWPAGE command does not affect the PAGESIZE value.PAGESIZE value.

• The command shown below specifies 6 blank lines The command shown below specifies 6 blank lines at the top of at the top of each pageeach page. If the page size is set to 55, . If the page size is set to 55, this will leave 49 lines for displaying output.this will leave 49 lines for displaying output.

SET NEWPAGE 6SET NEWPAGE 6

Page 20: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Output to the Computer Monitor ScreenOutput to the Computer Monitor Screen

• When you are testing a SQL program that will be When you are testing a SQL program that will be produce a printed report, it is sometimes useful to produce a printed report, it is sometimes useful to specify values for the LINESIZE, PAGESIZE, and specify values for the LINESIZE, PAGESIZE, and NEWPAGE values so that report output will fit on NEWPAGE values so that report output will fit on a computer monitor screen.a computer monitor screen.

• Typical values for screen output are shown below.Typical values for screen output are shown below.

SET LINESIZE 79SET LINESIZE 79SET PAGESIZE 24SET PAGESIZE 24SET NEWPAGE 0SET NEWPAGE 0

Page 21: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Output to the Computer Monitor ScreenOutput to the Computer Monitor Screen

• You will probably want the computer monitor You will probably want the computer monitor screen output to pause between pages so that you screen output to pause between pages so that you can review the report.can review the report.

• This can be accomplished by the SET PAUSE This can be accomplished by the SET PAUSE commands shown below. commands shown below.

SET PAUSE 'More . . .'SET PAUSE 'More . . .'SET PAUSE ONSET PAUSE ONSET PAUSE OFFSET PAUSE OFF

Page 22: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

CONTROL BREAK REPORTSCONTROL BREAK REPORTS

• A control break report organizes information into A control break report organizes information into meaningful groups. meaningful groups.

• We will organize the new report into groups We will organize the new report into groups according to each employee's social security according to each employee's social security number. The modified example program is listed number. The modified example program is listed below.below.

• The additional lines of code required to produce the The additional lines of code required to produce the control break report are highlighted in bold text.control break report are highlighted in bold text.

• Additionally, the decision was made to remove the Additionally, the decision was made to remove the report header and report footer. report header and report footer.

Page 23: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Example ModifiedExample Modified

REM Program: ch9-2.sqlREM Program: ch9-2.sqlREM Programmer: dbock; 3-20-2003REM Programmer: dbock; 3-20-2003REM Description: A sample program control break REM Description: A sample program control break

report.report.  TTITLE 'Project Information' TTITLE 'Project Information' BTITLE SKIP 1 CENTER 'Not for external dissemination.' BTITLE SKIP 1 CENTER 'Not for external dissemination.'   SET LINESIZE 55SET LINESIZE 55SET PAGESIZE 24SET PAGESIZE 24SET NEWPAGE 1SET NEWPAGE 1  COLUMN "Emp. Soc. Sec. #" FORMAT A16COLUMN "Emp. Soc. Sec. #" FORMAT A16COLUMN "Hours Worked" FORMAT 999.99COLUMN "Hours Worked" FORMAT 999.99

Page 24: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Example Cont’dExample Cont’d

CLEAR BREAKSCLEAR BREAKSBREAK ON "Emp. Soc. Sec. #" SKIP 2 ON REPORTBREAK ON "Emp. Soc. Sec. #" SKIP 2 ON REPORTCOMPUTE SUM OF "Hours Worked" ON "Emp. Soc. Sec. #“COMPUTE SUM OF "Hours Worked" ON "Emp. Soc. Sec. #“COMPUTE SUM OF "Hours Worked" ON REPORT SPOOL report9-COMPUTE SUM OF "Hours Worked" ON REPORT SPOOL report9-

2.lst2.lst  SELECT work_emp_ssn "Emp. Soc. Sec. #",SELECT work_emp_ssn "Emp. Soc. Sec. #", work_pro_number "Project #", work_hours "Hourswork_pro_number "Project #", work_hours "Hours Worked"Worked"FROM assignmentFROM assignmentORDER BY work_emp_ssn, work_pro_number;ORDER BY work_emp_ssn, work_pro_number;  SPOOL OFFSPOOL OFF

Page 25: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Sun Apr 14 page 1Sun Apr 14 page 1 Project InformationProject Information  Project Report #1 - prepared by D. BockProject Report #1 - prepared by D. Bock  Emp. Soc. Sec. # Project # Hours WorkedEmp. Soc. Sec. # Project # Hours Worked---------------- ---------- ---------------------------- ---------- ------------999111111 1 31.40999111111 1 31.40 2 8.502 8.50**************** ------------**************** ------------sum 39.90sum 39.90

999222222 10 34.50999222222 10 34.50 30 5.1030 5.10**************** ------------**************** ------------sum 39.60sum 39.60

999333333 3 42.10999333333 3 42.10**************** ------------**************** ------------

Not for external dissemination.Not for external dissemination.

Page 26: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

The BREAK CommandThe BREAK Command

• The BREAK command groups data rows for a control The BREAK command groups data rows for a control break report. The syntax of the BREAK command is:break report. The syntax of the BREAK command is:

BREAK ON (expression1, ON expression2, BREAK ON (expression1, ON expression2, …… \row\page\ \row\page\report) report) ……

[SKIP n | [SKIP] PAGE][SKIP n | [SKIP] PAGE][NODUPLICATES | DUPLICATES];[NODUPLICATES | DUPLICATES];

• The BREAK command can be used to break on an The BREAK command can be used to break on an expression, row, page, report, or more than one of expression, row, page, report, or more than one of these at a time. The BREAK command used in these at a time. The BREAK command used in example program is shown below. example program is shown below.

CLEAR BREAKSCLEAR BREAKS

BREAK ON "Emp. Soc. Sec. #" SKIP 2 ON REPORTBREAK ON "Emp. Soc. Sec. #" SKIP 2 ON REPORT

• The CLEAR BREAKS command clears any The CLEAR BREAKS command clears any previously established breaks.previously established breaks.

Page 27: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Output StyleOutput Style• The style of output shown in the example report is called The style of output shown in the example report is called

NONDUPLICATES, or NODUP because each group NONDUPLICATES, or NODUP because each group value (employee social security number) is shown only value (employee social security number) is shown only once.once.

• This is the default BREAK output method so there is no This is the default BREAK output method so there is no need to specify it. While this form of output diverges need to specify it. While this form of output diverges from the relational, two-dimensional, matrix format, it is from the relational, two-dimensional, matrix format, it is much easier for managers to read.much easier for managers to read.

• The NODUP default can be overwritten by specifying The NODUP default can be overwritten by specifying the keyword DUP with the BREAK command as is the keyword DUP with the BREAK command as is shown here. This will yield the purely relational, two-shown here. This will yield the purely relational, two-dimensional, matrix format for output.dimensional, matrix format for output.

BREAK ON "Emp. Soc. Sec. #" DUP SKIP 2BREAK ON "Emp. Soc. Sec. #" DUP SKIP 2

Page 28: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

SKIP and PAGE KeywordsSKIP and PAGE Keywords

• To enhance the readability of a report, one or more To enhance the readability of a report, one or more blank rows can be inserted after each social blank rows can be inserted after each social security number grouping. As we noted earlier, the security number grouping. As we noted earlier, the SKIP keyword inserts the blank rows. Our program SKIP keyword inserts the blank rows. Our program specified to skip two lines prior to beginning the specified to skip two lines prior to beginning the next report group. next report group.

• Replacing the keyword SKIP with PAGE will Replacing the keyword SKIP with PAGE will cause a cause a page ejectpage eject to occur after each grouping. to occur after each grouping.

• This will produce a report with each social security This will produce a report with each social security number beginning on a new page. This will also number beginning on a new page. This will also cause each group to be preceded by new column cause each group to be preceded by new column headings. headings.

Page 29: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

The COMPUTE CommandThe COMPUTE Command

• In order for a COMPUTE command to compute In order for a COMPUTE command to compute subtotals and totals properly it must be used in subtotals and totals properly it must be used in conjunction with a BREAK command.conjunction with a BREAK command.

• If you have not specified a BREAK command, If you have not specified a BREAK command, then a COMPUTE command will not produce any then a COMPUTE command will not produce any results!results!

• When used with BREAK, a COMPUTE command When used with BREAK, a COMPUTE command displays values that are computed for the BREAK displays values that are computed for the BREAK expression. The syntax of the COMPUTE expression. The syntax of the COMPUTE command is shown here. command is shown here.

COMPUTE {group function} OF {column_name | COMPUTE {group function} OF {column_name | column_name_alias,. . .} ON {break_column_name | ROW | PAGE | column_name_alias,. . .} ON {break_column_name | ROW | PAGE |

REPORT};REPORT};

Page 30: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

The SPOOL CommandThe SPOOL Command

• The SPOOL command routes the output from a The SPOOL command routes the output from a SQL*Plus program to the specified filename. SQL*Plus program to the specified filename.

• The SPOOL command shown below routes output The SPOOL command shown below routes output to a file named to a file named report9-2.lstreport9-2.lst..

• The "lst" filename extension is short for listing; The "lst" filename extension is short for listing; however, you can specify any filename extension however, you can specify any filename extension that you desire.that you desire.

• The SPOOL OFF command terminates writing to The SPOOL OFF command terminates writing to the output file.the output file.

SPOOL report9-2.lstSPOOL report9-2.lstSPOOL OFFSPOOL OFF

Page 31: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Additional BREAK Command DetailsAdditional BREAK Command Details

• The BREAK command in the example program specifies a The BREAK command in the example program specifies a break on a column as well as on a report. You can also break break on a column as well as on a report. You can also break on any kind of expression, on rows, and on pages.on any kind of expression, on rows, and on pages.

• The BREAK ON ROW command can be used to change report The BREAK ON ROW command can be used to change report spacing. The BREAK command shown below will insert a spacing. The BREAK command shown below will insert a blank line between each row of the blank line between each row of the assignmentassignment report. report.

BREAK ON ROW SKIP 1BREAK ON ROW SKIP 1

• A column break and a row break can be used together. In A column break and a row break can be used together. In conjunction, these two breaks create a double-spaced report conjunction, these two breaks create a double-spaced report that is still separated by column values. The command shown that is still separated by column values. The command shown here will produce a double-spaced report that also breaks at the here will produce a double-spaced report that also breaks at the end of the report. end of the report.

BREAK ON "Emp. Soc. Sec. #" SKIP 1 ON REPORT ON ROW SKIP 1BREAK ON "Emp. Soc. Sec. #" SKIP 1 ON REPORT ON ROW SKIP 1

Page 32: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Viewing Current BREAK and COMPUTE Viewing Current BREAK and COMPUTE Command SettingsCommand Settings

• Only one BREAK command can be active at a time.Only one BREAK command can be active at a time.• You can interactively replace the current BREAK You can interactively replace the current BREAK

command by typing a new command at the SQL> prompt.command by typing a new command at the SQL> prompt.• If you forget which BREAK command is active, simply If you forget which BREAK command is active, simply

type the command BREAK on a line by itself and type the command BREAK on a line by itself and SQL*Plus will display the break status.SQL*Plus will display the break status.

• Note that the default for the BREAK command is no Note that the default for the BREAK command is no duplicates (NODUP).duplicates (NODUP).

BREAKBREAKbreak on report nodupbreak on report nodup on Emp. Soc. Sec. # skip 2 nodupon Emp. Soc. Sec. # skip 2 nodup

Page 33: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Viewing Current BREAK and COMPUTE Viewing Current BREAK and COMPUTE Command SettingsCommand Settings

• Unlike BREAK, the COMPUTE command is cumulative. Unlike BREAK, the COMPUTE command is cumulative. • While you are testing a program, you may accumulate quite a While you are testing a program, you may accumulate quite a

number of COMPUTE settings. You can display the current number of COMPUTE settings. You can display the current settings by simply typing the COMPUTE command at the SQL> settings by simply typing the COMPUTE command at the SQL> prompt.prompt.

COMPUTECOMPUTECOMPUTE sum LABEL 'sum' OF Hours Worked ON Emp. Soc. Sec. #COMPUTE sum LABEL 'sum' OF Hours Worked ON Emp. Soc. Sec. #COMPUTE sum LABEL 'sum' OF Hours Worked ON REPORTCOMPUTE sum LABEL 'sum' OF Hours Worked ON REPORT

• You can clear COMPUTE settings by typing CLEAR COMPUTE You can clear COMPUTE settings by typing CLEAR COMPUTE at the SQL> prompt or by placing the command within a at the SQL> prompt or by placing the command within a program.program.

• When the command is used interactively, Oracle will respond as When the command is used interactively, Oracle will respond as shown below.shown below.

CLEAR COMPUTECLEAR COMPUTEcomputes clearedcomputes cleared

Page 34: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

CREATING MASTER-DETAIL CREATING MASTER-DETAIL REPORTSREPORTS

• A master-detail report is a form of control break report A master-detail report is a form of control break report because the report presents information that is "grouped.“because the report presents information that is "grouped.“

• The report typically displays data rows from more than The report typically displays data rows from more than one table.one table.

• Consider the one-to-many relationship between the Consider the one-to-many relationship between the departmentdepartment and and projectproject tables for the Company as tables for the Company as described in Appendix A.described in Appendix A.

• Each department controls numerous projects, and a project Each department controls numerous projects, and a project belongs to a single department.belongs to a single department.

• In this situation, the rows in the In this situation, the rows in the departmentdepartment table are table are "master" rows because the "master" rows because the departmentdepartment table is on the "one" table is on the "one" side of the one-to-many relationship.side of the one-to-many relationship.

• The associated The associated projectproject table rows provide the "detail" table rows provide the "detail" information. information.

Page 35: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

• ExampleExample• Program Program ch9-3.sqlch9-3.sql will produce the master-detail report for the will produce the master-detail report for the

department-projectdepartment-project relationship. relationship.

REM Program: ch9-3.sqlREM Program: ch9-3.sqlREM Programmer: dbock; Date: 3-20-2003REM Programmer: dbock; Date: 3-20-2003REM Description: A sample Master-Detail reportREM Description: A sample Master-Detail reportREM set page size, line size, new page spacing for screen display. REM set page size, line size, new page spacing for screen display. SET LINESIZE 65SET LINESIZE 65SET PAGESIZE 12SET PAGESIZE 12SET NEWPAGE 1SET NEWPAGE 1REM define department variableREM define department variableCOLUMN pro_dept_number NEW_VALUE dept_number_var COLUMN pro_dept_number NEW_VALUE dept_number_var

NOPRINTNOPRINTREM set column sizes based on alias column namesREM set column sizes based on alias column namesCOLUMN dpt_name FORMAT A18COLUMN dpt_name FORMAT A18COLUMN pro_name FORMAT A15COLUMN pro_name FORMAT A15COLUMN pro_location FORMAT A15COLUMN pro_location FORMAT A15TTITLE CENTER 'Department Number:' dept_number_var SKIP 2TTITLE CENTER 'Department Number:' dept_number_var SKIP 2BTITLE SKIP 1 CENTER 'Not for external dissemination.' BTITLE SKIP 1 CENTER 'Not for external dissemination.'

Page 36: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

• Example cont’dExample cont’d

BREAK ON pro_dept_number SKIP PAGEBREAK ON pro_dept_number SKIP PAGE

SELECT pro_dept_number, dpt_name, pro_name, pro_locationSELECT pro_dept_number, dpt_name, pro_name, pro_location

FROM department d, project pFROM department d, project p

WHERE d.dpt_no = p.pro_dept_number AND WHERE d.dpt_no = p.pro_dept_number AND

pro_dept_number IN (3, 7)pro_dept_number IN (3, 7)

ORDER BY pro_dept_number; ORDER BY pro_dept_number;

• The report produced is shown next. The report produced is shown next.

Page 37: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Department Number: 3Department Number: 3

DPT_NAME PRO_NAME PRO_LOCATIONDPT_NAME PRO_NAME PRO_LOCATION------------------ ----------------- --------------------------------- ----------------- ---------------Admin and Records Inventory MarinaAdmin and Records Inventory MarinaAdmin and Records Pay Benefits MarinaAdmin and Records Pay Benefits Marina

Not for external dissemination.Not for external dissemination.More . . .More . . .

Department Number: 7Department Number: 7

DPT_NAME PRO_NAME PRO_LOCATIONDPT_NAME PRO_NAME PRO_LOCATION------------------ --------------- --------------------------------- --------------- ---------------Production Order Entry St. LouisProduction Order Entry St. LouisProduction Payroll CollinsvilleProduction Payroll CollinsvilleProduction Receivables EdwardsvilleProduction Receivables Edwardsville

Not for external dissemination. Not for external dissemination.

Page 38: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

MASTER-DETAIL REPORTSMASTER-DETAIL REPORTS• A typical master-detail report format includes information in the A typical master-detail report format includes information in the

top title report line that identifies the "master column" that top title report line that identifies the "master column" that controls the page breaks.controls the page breaks.

• You can reference a column value in a top title by first storing You can reference a column value in a top title by first storing the column value to a the column value to a program variableprogram variable..

• You then specify the program variable name in the TTITLE You then specify the program variable name in the TTITLE command.command.

• A special form of the COLUMN command is used to define a A special form of the COLUMN command is used to define a program variable as shown below. program variable as shown below.

• The actual COLUMN command from program The actual COLUMN command from program ch9-3.sqlch9-3.sql is also is also shown below. shown below.

• The NEW_VALUE clause defines the variable name. You must The NEW_VALUE clause defines the variable name. You must follow Oracle's naming rules when naming program variables. follow Oracle's naming rules when naming program variables.

COLUMN column_name NEW_VALUE variable_name COLUMN column_name NEW_VALUE variable_name [options] [options]

COLUMN pro_dept_number NEW_VALUE dept_number_var COLUMN pro_dept_number NEW_VALUE dept_number_var NOPRINTNOPRINT

Page 39: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Using Views in Master-Detail ReportsUsing Views in Master-Detail ReportsREM Program: ch9-4.sqlREM Program: ch9-4.sqlREM Programmer: dbock; 3-20-2003REM Programmer: dbock; 3-20-2003REM Description: The revised Master-Detail program with a REM Description: The revised Master-Detail program with a

View.View.  REM set page size, line size, new page for screen display.REM set page size, line size, new page for screen display.SET LINESIZE 75;SET LINESIZE 75;SET PAGESIZE 12;SET PAGESIZE 12;SET NEWPAGE 1;SET NEWPAGE 1;  REM Create a view to be used in the SELECT command later.REM Create a view to be used in the SELECT command later.CREATE OR REPLACE VIEW project_department (project_no, CREATE OR REPLACE VIEW project_department (project_no,

dept_name,dept_name, project_name, location) ASproject_name, location) AS SELECT pro_dept_number, dpt_name, pro_name, pro_locationSELECT pro_dept_number, dpt_name, pro_name, pro_location FROM department d, project pFROM department d, project p WHERE d.dpt_no = p.pro_dept_number AND WHERE d.dpt_no = p.pro_dept_number AND pro_dept_number IN (3, 7)pro_dept_number IN (3, 7) ORDER BY pro_dept_number; ORDER BY pro_dept_number;

Page 40: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Using Views in Master-Detail ReportsUsing Views in Master-Detail Reports

COLUMN dept_name NEW_VALUE dpt_name_var NOPRINTCOLUMN dept_name NEW_VALUE dpt_name_var NOPRINT  COLUMN dept_name FORMAT A18COLUMN dept_name FORMAT A18COLUMN project_name FORMAT A15COLUMN project_name FORMAT A15COLUMN location FORMAT A15COLUMN location FORMAT A15  TTITLE CENTER 'Department Name: ' dpt_name_var SKIP 2 TTITLE CENTER 'Department Name: ' dpt_name_var SKIP 2 BTITLE SKIP 1 CENTER 'Not for external dissemination.' BTITLE SKIP 1 CENTER 'Not for external dissemination.'   BREAK ON project_no SKIP PAGE;BREAK ON project_no SKIP PAGE;  SELECT project_no, dept_name, project_name, locationSELECT project_no, dept_name, project_name, locationFROM project_department;FROM project_department;  

• The program creates a view named The program creates a view named project-departmentproject-department. This . This view assigns meaningful names to the selected columns, joins view assigns meaningful names to the selected columns, joins the the departmentdepartment and and projectproject tables, and orders the output of tables, and orders the output of rows by department number of the department controlling rows by department number of the department controlling each project.each project.

Page 41: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Using Views in Master-Detail ReportsUsing Views in Master-Detail Reports• The revised COLUMN command uses a The revised COLUMN command uses a

NEW_VALUE clause to store the value of the NEW_VALUE clause to store the value of the dept_namedept_name column of the view to a variable named column of the view to a variable named dpt_name_var.dpt_name_var.

• This variable is used in the TTITLE command to This variable is used in the TTITLE command to display the department name at the top of each page. display the department name at the top of each page.

• The BREAK command still breaks on the The BREAK command still breaks on the project_noproject_no column as the master column.column as the master column.

• Finally, the SELECT statement is greatly simplified Finally, the SELECT statement is greatly simplified because the program is now selecting information from because the program is now selecting information from the view.the view.

• If the view had been previously created, then the code If the view had been previously created, then the code to create the view could be deleted from program to create the view could be deleted from program ch9-4.sql.ch9-4.sql.

Page 42: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Department Name: Admin and RecordsDepartment Name: Admin and Records  PROJECT_NO PROJECT_NAME LOCATIONPROJECT_NO PROJECT_NAME LOCATION---------- --------------- ------------------------- --------------- --------------- 3 Inventory Marina3 Inventory Marina Pay Benefits MarinaPay Benefits Marina     Not for external dissemination.Not for external dissemination.More . . .More . . .   Department Name: ProductionDepartment Name: Production  PROJECT_NO PROJECT_NAME LOCATIONPROJECT_NO PROJECT_NAME LOCATION---------- --------------- ------------------------- --------------- --------------- 7 Order Entry St. Louis7 Order Entry St. Louis Payroll CollinsvillePayroll Collinsville Receivables EdwardsvilleReceivables Edwardsville     Not for external dissemination.Not for external dissemination.

Page 43: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

USING VARIABLES FOR INTERACTIVE USING VARIABLES FOR INTERACTIVE REPORTINGREPORTING

REM Program: ch9-5.sqlREM Program: ch9-5.sqlREM Programmer: dbock; 3-20-2003REM Programmer: dbock; 3-20-2003REM Description: Program with interactive variables.REM Description: Program with interactive variables.  SET LINESIZE 60;SET LINESIZE 60;SET PAGESIZE 12;SET PAGESIZE 12;SET NEWPAGE 1;SET NEWPAGE 1;  COLUMN today NEW_VALUE date_varCOLUMN today NEW_VALUE date_varSELECT TO_CHAR(SYSDATE, 'MM/DD/YY') todaySELECT TO_CHAR(SYSDATE, 'MM/DD/YY') todayFROM dual;FROM dual;  COLUMN pro_name NEW_VALUE pro_name_var NOPRINTCOLUMN pro_name NEW_VALUE pro_name_var NOPRINTCOLUMN pro_number NEW_VALUE pro_number_var NOPRINTCOLUMN pro_number NEW_VALUE pro_number_var NOPRINTCOLUMN "Department" FORMAT A18COLUMN "Department" FORMAT A18

Page 44: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

USING VARIABLES FOR INTERACTIVE USING VARIABLES FOR INTERACTIVE REPORTINGREPORTING

COLUMN "SSN" FORMAT A12COLUMN "SSN" FORMAT A12COLUMN "Employee Name" FORMAT A20COLUMN "Employee Name" FORMAT A20COLUMN "Hours" FORMAT 999.99COLUMN "Hours" FORMAT 999.99  CLEAR BREAKSCLEAR BREAKSCLEAR COMPUTESCLEAR COMPUTESBREAK ON "Department" ON REPORTBREAK ON "Department" ON REPORTCOMPUTE SUM OF "Hours" ON REPORTCOMPUTE SUM OF "Hours" ON REPORT  ACCEPT project_no_var PROMPT 'Enter a project number: 'ACCEPT project_no_var PROMPT 'Enter a project number: 'PAUSE Press the Enter Key to continue.PAUSE Press the Enter Key to continue.  TTITLE LEFT date_var CENTER 'Project Name: ' pro_name_var -TTITLE LEFT date_var CENTER 'Project Name: ' pro_name_var - RIGHT 'Page:' FORMAT 999 sql.pno SKIP 1 - RIGHT 'Page:' FORMAT 999 sql.pno SKIP 1 - CENTER 'Project Number:' pro_number_var SKIP 2 CENTER 'Project Number:' pro_number_var SKIP 2   

Page 45: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

USING VARIABLES FOR INTERACTIVE USING VARIABLES FOR INTERACTIVE REPORTINGREPORTING

SPOOL project.lstSPOOL project.lst  SELECT pro_number, pro_name, dpt_name "Department",SELECT pro_number, pro_name, dpt_name "Department", SUBSTR(work_emp_ssn,1,3)||'-'||SUBSTR(work_emp_ssn,1,3)||'-'||

SUBSTR(work_emp_ssn,4,2)||'-'||SUBSTR(work_emp_ssn,6,4) SUBSTR(work_emp_ssn,4,2)||'-'||SUBSTR(work_emp_ssn,6,4) "SSN","SSN",

emp_last_name||', '||emp_last_name||', '|| emp_first_name "Employee Name", emp_first_name "Employee Name", work_hours "Hours"work_hours "Hours"FROM project p, assignment a, employee e, department dFROM project p, assignment a, employee e, department dWHERE p.pro_number = a.work_pro_number ANDWHERE p.pro_number = a.work_pro_number AND a.work_emp_ssn = e.emp_ssn ANDa.work_emp_ssn = e.emp_ssn AND d.dpt_no = p.pro_dept_number ANDd.dpt_no = p.pro_dept_number AND p.pro_number = '&project_no_var‘p.pro_number = '&project_no_var‘

ORDER BY pro_number, emp_last_name, emp_first_name;ORDER BY pro_number, emp_last_name, emp_first_name;  SPOOL OFFSPOOL OFF

Page 46: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Executing Program Ch9-5.SqlExecuting Program Ch9-5.Sql SQL> start ch9-5.sqlSQL> start ch9-5.sqlMore . . .More . . .

TODAYTODAY----------------04/14/0204/14/02

Enter a project number: 30Enter a project number: 30Press the Enter Key to continue.Press the Enter Key to continue.

old 9: p.pro_number = '&project_no_var'old 9: p.pro_number = '&project_no_var'new 9: p.pro_number = '30'new 9: p.pro_number = '30'More . . .More . . .

04/14/02 Project Name: Pay Benefits Page: 104/14/02 Project Name: Pay Benefits Page: 1 Project Number: 30Project Number: 30  Department SSN Employee Name HoursDepartment SSN Employee Name Hours------------------ ------------ -------------------- ------------------------- ------------ -------------------- -------Admin and Records 999-22-2222 Amin, Hyder 5.10Admin and Records 999-22-2222 Amin, Hyder 5.10 999-55-5555 Joyner, Suzanne 19.20999-55-5555 Joyner, Suzanne 19.20 999-88-7777 Markis, Marcia 30.80999-88-7777 Markis, Marcia 30.80****************** -------****************** ------- 55.1055.10

Page 47: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Defining User VariablesDefining User Variables• You can define variables with the SQL*Plus You can define variables with the SQL*Plus

DEFINE command.DEFINE command.• The command shown here defines a variable The command shown here defines a variable

name_varname_var, and assigns it the value "Bordoloi." , and assigns it the value "Bordoloi."

DEFINE name_var = BordoloiDEFINE name_var = Bordoloi

• If you need to know what variables have been If you need to know what variables have been defined for your working session, enter the DEFINE defined for your working session, enter the DEFINE command by itself at the SQL> prompt and all command by itself at the SQL> prompt and all current variable definitions will be displayed. current variable definitions will be displayed.

• You can also delete a variable with the UNDEFINE You can also delete a variable with the UNDEFINE <variable_name> command.<variable_name> command.

Page 48: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Defining User VariablesDefining User VariablesDEFINE name_var = BordoloiDEFINE name_var = BordoloiSELECT emp_last_name, emp_first_name, SELECT emp_last_name, emp_first_name,

emp_date_of_birthemp_date_of_birthFROM employeeFROM employeeWHERE emp_last_name = '&name_var'WHERE emp_last_name = '&name_var'//

  EMP_LAST_NAME EMP_FIRST_NAME EMP_DATE_ EMP_LAST_NAME EMP_FIRST_NAME EMP_DATE_ ------------------------- -------------------------- ------------------------------------------ -------------------------- -----------------Bordoloi Bordoloi Bijoy Bijoy 10-NOV- 10-NOV-

6767

Page 49: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Passing Parameter Values Through the Passing Parameter Values Through the START CommandSTART Command

• You can pass a value to a program at run time as a You can pass a value to a program at run time as a parameter of the START command. parameter of the START command.

• Use an ampersand (Use an ampersand (&&) followed by a numeral in the ) followed by a numeral in the command file; for example, command file; for example, &1&1 in place of the in place of the substitution variable.substitution variable.

• Each time you run the command file, the START Each time you run the command file, the START command replaces the command replaces the &1&1 parameter in the file with parameter in the file with the first value (called an argument) listed after a the first value (called an argument) listed after a START START filenamefilename command. command.

• You can use as many ampersand-parameter variables You can use as many ampersand-parameter variables as is needed in the program.as is needed in the program.

• The arguments of the START command are separated The arguments of the START command are separated by commas. by commas.

Page 50: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

ExampleExampleREM ch9-6.sql – Example passing argumentsREM ch9-6.sql – Example passing arguments

SELECT emp_last_name, emp_ssn, emp_dpt_numberSELECT emp_last_name, emp_ssn, emp_dpt_number

FROM employeeFROM employee

WHERE emp_last_name = '&1' OR emp_dpt_number = '&2';WHERE emp_last_name = '&1' OR emp_dpt_number = '&2';

REM end of programREM end of program

SQL> start ch9-6.sql Bock 1SQL> start ch9-6.sql Bock 1

old 3: WHERE emp_last_name = '&1' OR emp_dpt_number = '&2'old 3: WHERE emp_last_name = '&1' OR emp_dpt_number = '&2'

new 3: WHERE emp_last_name = 'Bock' OR emp_dpt_number = '1'new 3: WHERE emp_last_name = 'Bock' OR emp_dpt_number = '1'

More . . .More . . .

  

EMP_LAST_NAME EMP_SSN EMP_DPT_NUMBEREMP_LAST_NAME EMP_SSN EMP_DPT_NUMBER

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

Bordoloi 999666666 1Bordoloi 999666666 1

Bock 999111111 7Bock 999111111 7

Page 51: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Clearing the Computer Monitor ScreenClearing the Computer Monitor Screen

• If you need to clear the computer monitor If you need to clear the computer monitor screen before displaying a report (or at any screen before displaying a report (or at any other time), include the CLEAR command other time), include the CLEAR command with its SCREEN clause at the appropriate with its SCREEN clause at the appropriate point in your command file, using the format point in your command file, using the format shown here. shown here.

CLEAR SCREENCLEAR SCREEN

Page 52: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Formatting Aggregate Function TitlesFormatting Aggregate Function Titles

• The COMPUTE command produces a standard title of The COMPUTE command produces a standard title of 'sum' as a label for the column that is aggregated. 'sum' as a label for the column that is aggregated.

• This also applies to the other aggregate functions; each This also applies to the other aggregate functions; each function has its own standard title.function has its own standard title.

• SQL*Plus allows you to change the aggregate function SQL*Plus allows you to change the aggregate function title to a more meaningful title.title to a more meaningful title.

• The COMPUTE commands shown below revise those The COMPUTE commands shown below revise those used earlier in program used earlier in program ch9-2.sqlch9-2.sql (run program (run program ch9-ch9-2a.sql2a.sql). ).

• Each employee's sum of total hours worked is labeled Each employee's sum of total hours worked is labeled as 'Employee Hours,' and the report sum of total hours as 'Employee Hours,' and the report sum of total hours is labeled as 'Total Hours.'is labeled as 'Total Hours.'

Page 53: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

COMPUTE SUM LABEL 'Employee Hours' OFCOMPUTE SUM LABEL 'Employee Hours' OF

"Hours Worked" ON "Emp. Soc. Sec. #" "Hours Worked" ON "Emp. Soc. Sec. #"

COMPUTE SUM LABEL 'Total Hours' OF "Hours Worked" ON COMPUTE SUM LABEL 'Total Hours' OF "Hours Worked" ON REPORTREPORT

Following Figure gives pages #1 and #4 of the reportFollowing Figure gives pages #1 and #4 of the report

Page 54: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Sun Apr 14 page 1Sun Apr 14 page 1 Project InformationProject Information  Emp. Soc. Sec. # Project # Hours WorkedEmp. Soc. Sec. # Project # Hours Worked---------------- ---------- ---------------------------- ---------- ------------999111111 1 31.40999111111 1 31.40 2 8.502 8.50**************** ------------**************** ------------Employee Hours 39.90Employee Hours 39.90    999222222 10 34.50999222222 10 34.50 30 5.1030 5.10**************** ------------**************** ------------Employee Hours 39.60Employee Hours 39.60    999333333 3 42.10999333333 3 42.10**************** ------------**************** ------------Employee Hours 42.10Employee Hours 42.10

Not for external dissemination.Not for external dissemination.

  

Page 55: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

--------- pages 2 and 3 would be printed here ------------------ pages 2 and 3 would be printed here ---------  Sun Apr 14 page 4Sun Apr 14 page 4 Project InformationProject Information  Emp. Soc. Sec. # Project # Hours WorkedEmp. Soc. Sec. # Project # Hours Worked---------------- ---------- ---------------------------- ---------- ------------   ------------------------Total Hours 284.20Total Hours 284.20         Not for external dissemination.Not for external dissemination.  

Page 56: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

Changing Column HeadingsChanging Column Headings • When displaying column headings, you can either use the When displaying column headings, you can either use the

default heading which is the column name, or you can default heading which is the column name, or you can change the heading with the COLUMN command. change the heading with the COLUMN command.

• The COLUMN command's HEADING clause can be used to The COLUMN command's HEADING clause can be used to assign meaningful column headings. assign meaningful column headings.

• If the new heading is a single word, the heading can be typed If the new heading is a single word, the heading can be typed as is done for the as is done for the emp_ssn columnemp_ssn column heading of SSN. heading of SSN.

• If the heading is more than one word, the heading must be If the heading is more than one word, the heading must be enclosed in single or double-quotes as is shown for the enclosed in single or double-quotes as is shown for the emp_last_nameemp_last_name heading of "Last Name." heading of "Last Name."

• If you want to display a column heading on more than one If you want to display a column heading on more than one line, use a vertical bar (|) where you want to begin a new line line, use a vertical bar (|) where you want to begin a new line as is done for the as is done for the emp_first_nameemp_first_name column. column.

Page 57: Chapter 9 :  SQL*PLUS REPORTS

Bordoloi and BockBordoloi and Bock

ExampleExample

COLUMN emp_ssn HEADING SSN;COLUMN emp_ssn HEADING SSN;

COLUMN emp_last_name HEADING "Last Name";COLUMN emp_last_name HEADING "Last Name";

COLUMN emp_first_name HEADING COLUMN emp_first_name HEADING "First|Name";"First|Name";

  • The new headings will remain in effect until you enter The new headings will remain in effect until you enter

different headings, reset each column's format, or exit different headings, reset each column's format, or exit SQL*Plus. SQL*Plus.