SQLPlus命令使用指南(三)
2024-07-21 02:41:10
供稿:網友
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 {exprcolumnalias} ...
ON {exprcolumnaliasREPORTROW} ...]
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
未完待續。。。。。