第131章 SQL函数 SQUARE
返回数字平方的标量数值函数。
大纲
SQUARE(numeric-expression)
参数
-
numeric-expression- 解析为数值的表达式。
SQUARE 返回 NUMERIC 或 DOUBLE 数据类型。如果 numeric-expression 是数据类型 DOUBLE,则 SQUARE 返回 DOUBLE;否则,它返回 NUMERIC。
描述
SQUARE 返回数值表达式的平方。如果传递 NULL 值,SQUARE 返回 NULL。
SQUARE 返回的精度和小数位数与 SQL 乘法运算符返回的相同。
示例
以下嵌入式 SQL 示例返回整数 0 到 10 的平方:
/// d ##class(PHA.TEST.SQLFunction).Square()
ClassMethod Square()
{
s a = 0
while a < 11 {
&sql(
SELECT SQUARE(:a) INTO :b
)
if SQLCODE '= 0 {
w !,"Error code ",SQLCODE
} else {
w !,"The square of ",a," = ",b
s a = a + 1
}
}
}
DHC-APP>d ##class(PHA.TEST.SQLFunction).Square()
The square of 0 = 0
The square of 1 = 1
The square of 2 = 4
The square of 3 = 9
The square of 4 = 16
The square of 5 = 25
The square of 6 = 36
The square of 7 = 49
The square of 8 = 64
The square of 9 = 81
The square of 10 = 100








网友评论