** SQLPlus 命令使用指南 (三 ) **
/*------------------------------------------------------------------------
作者:翁彦
时间:2004-3-9
欢迎转载,请保留作者信息
/*-----------------------------------------------------------------------------------------------------
(3) Break 命令
利用 Break 你可以打印出报表需要的一些内容,如小计,重复的列值不显示,或者每个分组插入一个空行等等。
清除 break 设置, clear breaks 。
语法:
BREAK
-----
Specifies where and how to make format changes to a report.
BRE[AK] [ON report_element [action [action]]] ...
where report_element has the following syntax:
{column | expression | ROW | REPORT}
and where action has the following syntax:
[SKI[P] n | [SKI[P]] PAGE] [NODUP[LICATES] | DUP[LICATES]]
说明如下:
sql>break on deptno
得到的结果如图 4

图 4
通过对某个列设置 break 命令,我们去掉了重复显示 deptno 的值。请仔细对比一下没有 break 的情况。这种用法称为 break column 的用法。 BREAK 命令中的列应该要出现在 SQL 语句的 order by 中,如果 order by 中有多个列,也有多个列的 break 用法。 如图 5 。
** Break ** ** 参数的说明 ** ** **
¨ Skip[n], 在每个分组值出现前,自动插入 n 个空行
¨ Skip page, 在每个分组值出现前,自动换页
¨ BREAK ON ROW SKIP[n], 每一行后面插入 n 个空行。
¨ Nodup 重复的显示空, dup 重复的也显示。
BREAK 好比定义了一个事件,当值发生了变化后,可以对查询的结果执行一个特定的操作。 BREAK 和 COMPUTE 命令一起用,就可以产生小计等报表效果。

图 5
(4) COMPUTE 命令
在结果的最后显示一行统计行。如果有多个 COMPUTE ,那么只有最后一个 COMPUTE 才起作用。 Clear computes 删除所有设定的 compute 。
语法:
COMPUTE
-------
Calculates and prints summary lines, using various standard
computations, on subsets of selected rows. It also lists all
COMPUTE definitions.
COMP[UTE] [function [LAB[EL] text] ...
OF {expr|column|alias} ...
ON {expr|column|alias|REPORT|ROW} ...]
COMPUTE 和 BREAK 一起使用的。没有 BREAK 语句的 COMPUTE 没有任何效果。一般的用法如下:
BREAK ON break_column
COMPUTE function LABEL label_name OF column column column
... ON break_column
COMPUTE 执行的计算操作主要有:
SUM
|
Computes the sum of the values in the column.
---|---
MINIMUM
|
Computes the minimum value in the column.
MAXIMUM
|
Computes the maximum value in the column.
AVG
|
Computes the average of the values in the column.
STD
|
Computes the standard deviation of the values in the column.
VARIANCE
|
Computes the variance of the values in the column.
COUNT
|
Computes the number of non-null values in the column.
NUMBER
|
Computes the number of rows in the column.
下面是一个 COMPUTE 计算的例子。如图 6

图 6
** COMPUTE ** ** 参数的说明 ** ** **
¨ LABEL 为计算指定一个名称。如 COMPUTE SUM LABEL ‘TOTAL’ OF SAL ON JOB ,那么在小计这一行,会显示 TOTAL ,而不是缺省的 sum
不需要打印任何标签,就使用 DUMMY 。如图 7 , dummy 的使用在 sql*plus 报表制作上还是很有用的。

图7
未完待续。。。。。