SQLPlus命令使用指南(三)

类别:数据库 点击:0 评论:0 推荐:

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

未完待续。。。。。

本文地址:http://com.8s8s.com/it/it20968.htm