SQLPlus命令使用指南(三)
/*------------------------------------------------------------------------
作者:翁彥
時間:2004-3-9
歡迎轉載,請保留作者信息
/*-----------------------------------------------------------------------------------------------------
(3) Break命令<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
利用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執行的計算操作主要有:
Computes the sum of the values in the column. | |
Computes the minimum value in the column. | |
Computes the maximum value in the column. | |
Computes the average of the values in the column. | |
Computes the standard deviation of the values in the column. | |
Computes the variance of the values in the column. | |
Computes the number of non-null values in the column. | |
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
未完待續。。。。。