Transact-SQL 参考

POWER

返回给定表达式乘指定次方的值。

语法

POWER ( numeric_expression , y )

参数

numeric_expression

是精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)。

y

numeric_expression 的次方。y 可以是精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)。

返回类型

numeric_expression 相同。

示例
A. 使用 POWER 显示结果 0.0

本示例显示返回结果 0.0 的浮点下溢。

SELECT POWER(2.0, -100.0)
GO

下面是结果集:

------------------------------------------
0.0

(1 row(s) affected)
B. 使用 POWER

本示例显示 21 到 24 的 POWER 结果。

DECLARE @value int, @counter int
SET @value = 2
SET @counter = 1

WHILE @counter < 5
   BEGIN
      SELECT POWER(@value, @counter)
      SET NOCOUNT ON
      SET @counter = @counter + 1
      SET NOCOUNT OFF
   END
GO

下面是结果集:

----------- 
2           

(1 row(s) affected)

----------- 
4           

(1 row(s) affected)

----------- 
8           

(1 row(s) affected)

----------- 
16          

(1 row(s) affected)

请参见

decimal 和 numeric

float 和 real

int、smallint 和 tinyint

数学函数

money 和 smallmoney