Professional Documents
Culture Documents
SQL * Plus to create an actual formatted report. Some of the formatting features available
in SQL* Plus include report headers and footers, formatting models for column data,
suppression of duplicate data for group reports and calculations. There are several
formatting options are available but only the most commonly used features.Most
elaborate reports are created using various application software and report generators.
Command Description
COLUMN COMMAND
The COLUMN command can be used to format both a column heading and the data
being displayed within the column, depending on the option(s) used . The basic syntax of
the COLUMN command is
Option Description
FORMAT Option:-
The format option allows to apply a format model to the data displayed within a
column. It used to format displaying values and adding additional symbols are given
below
A Book’s retail price of $54.50 was displayed as 54.5.The format option allows to
display the insignificant zero in output. Also include the dollar sign so the retail price
displayed as $54.50.
HEADING OPTION:
The heading option of the COLUMN command is used to specify a column heading for a
particular column. The report column headings are simply the BOOKS table’s column
names. The heading option is similar to the use of a column alias. It provides a
substitute heading for the display of the output.
1. A column name assigned by the HEADING option of the COLUMN command cannot
be referenced in a SELECT statement.
2. A column name assigned by the HEADING option can contain line breaks. In other
words the column name can be displayed on more than one line.
NULL Option
Some reports contain NULL values. In some instances, blank spaces may be appropriate
For example , consider the orders Just Lee books ships to its customers .If management
wants a report to view the lag time for shipping current orders and substitute the words
“NOT SHIPPED’ for any NULL values that occur in the shipdate column.
A headers serves as the title for a report. The header and footer of a report are set with the
TTITLE and BTITLE commands respectively. The TTITLE command indicates the text
or variables(page number) to be displayed at the top of the report. The BTITLE command
defines what is to be printed at the bottom of the report.
The syntax for both the TTITLE and BTITLE command are given below
Option Description
CENTER Centers data to be displayed between the
left and right margins of a report
FORMAT Applies a format model to data to be
displayed(Same as COLUMN command)
LEFT Aligns data to be displayed to the left
margin of the report
RIGHT Aligns data to be displayed to the right
margin of the report
SKIP n Indicates the number of lines to skip
before the display of data resumes
[text|variable]
It means that the alignment and FORMAT options can be applied either to text entered
as literal string or to SQL* Plus variables. Some of the SQL variables.
Variable Description
SQL.LNO Current line number
SQL.PNO Current page number
SQL.RELEASE Current Oracle release number
SQL.USER Current User Name
LINESIZE:
The TTITLE command can be used to create the report heading How the center or left
and right determined . It based on LINESIZE If LINESIZE set to 100 then the center of
the report will be 50 characters from the margin.
BREAK Command:
The BREAK command is used to suppress duplicate data in a report. The syntax for the BREAK
command us shown.
The effectiveness of the BREAK command is determined by how data are sorted in the SELECT
statement. The contents of the specified column are printed once, and the printing for all
subsequent rows is suppressed until the value in the column changes.
SET LINESIZE 32
SET PAGESIZE 27
TTITLE CENTER ‘Amount Due Per Order’ SKIP 2
BTITLE LEFT ‘Run By : ’ SQL.USER FORMAT A5
COLUMN total FORMAT 999999.99
BREAK ON customer# SKIP 1
SELECT customer#,order#,sum(retail*quantity) total from customers NATURAL JOIN orders
NATURAL JOIN orderitems NATURAL JOIN books group by customer#,order# order by
customer#;
CLEAR command
The clear command is used to clear the settings applied to the BREAK and COLUMN
commands. The settings applied to these commands are valid even after the report has been
finished. Any time that use the COLUMN or BREAK commands in a script always clear those
commands at the end of the script. So it will not affect any subsequent reports. The syntax for the
CLEAR command is
CLEAR COLUMN|BREAK
SET LINESIZE 32
SET PAGESIZE 27
TTITLE CENTER ‘Amount Due Per Order’ SKIP 2
BTITLE LEFT ‘Run By : ’ SQL.USER FORMAT A5
COLUMN total FORMAT 999999.99
BREAK ON customer# SKIP 1
SELECT customer#,order#,sum(retail*quantity) total from customers NATURAL JOIN orders
NATURAL JOIN orderitems NATURAL JOIN books group by customer#,order# order by
customer#;
CLEAR BREAK
CLEAR COLUMN
COMPUTE COMMAND:
To determine the total amount due for each customer owes by including the COMPUTING
command. The COMPUTE command can be included with the AVG,SUM,COUNT,MAX or
MIN keywords to determine average,totals,number of occurrences, the highest value or the lowest
value respectively.
SET LINESIZE 32
SET PAGESIZE 27
TTITLE CENTER ‘Amount Due Per Order’ SKIP 2
BTITLE LEFT ‘Run By : ’ SQL.USER FORMAT A5
COLUMN total FORMAT 999999.99
BREAK ON customer# SKIP 1
SELECT customer#,order#,sum(retail*quantity) total from customers NATURAL JOIN orders
NATURAL JOIN orderitems NATURAL JOIN books group by customer#,order# order by
customer#;
COMPUTE SUM OF total on customer#
CLEAR BREAK
CLEAR COLUMN
SPOOL Command
The results displayed on the computer monitor can also be redirected to a text computer file that
can than be printed through a word-processing program.
SPOOL D:\FILENAME
CLEAR COLUMN
SPOOL C:\REPORTRESULTS.TXT
SET LINESIZE 32
SET PAGESIZE 27
TTITLE CENTER ‘Amount Due Per Order’ SKIP 2
BTITLE LEFT ‘Run By : ’ SQL.USER FORMAT A5
COLUMN total FORMAT 999999.99
BREAK ON customer# SKIP 1
SELECT customer#,order#,sum(retail*quantity) total from customers NATURAL JOIN orders
NATURAL JOIN orderitems NATURAL JOIN books group by customer#,order# order by
customer#;
COMPUTE SUM OF total on customer#
SPOOL OFF
CLEAR BREAK
CLEAR COLUMN
Create view inventory as select isbn,title,retail from books with read only;