如何在sql中编写电源过程?

时间:2019-01-08 11:25:30

标签: sql-server tsql

@CucumberOptions(
    features = "@target/rerun.txt"
    , glue = {"steps"}
    , monochrome = true
    , format = {
    "pretty",
    "html:target/cucumber-pretty",
    "json:target/CucumberTestReport.json",
    "rerun:target/rerun.txt"
})

public class FailedTestRunner extends AbstractTestNGCucumberTests {}

2 个答案:

答案 0 :(得分:2)

您可以尝试一下。

CREATE PROCEDURE hochdrei
    @x INT
AS
BEGIN
    SELECT power(@x, 3)
END

请注意,在上述SP中,您会将X值作为输入参数传递给存储过程。

您可以像这样调用存储过程。

EXEC hochdrei 2
  

结果:8

如果您不想将X作为参数传递,则将在下面使用。

CREATE PROCEDURE hochdrei        
AS
BEGIN
    DECLARE @x INT=2
    SELECT power(@x, 3)
END

将SP称为;

EXEC hochdrei
  

结果:8

答案 1 :(得分:0)

CREATE PROCEDURE Exponentiation
    @Base FLOAT,
    @Exponent FLOAT
AS
BEGIN
    SELECT POWER(@Base, @Exponent) AS Power
END

执行示例:

EXEC Exponentiation -- Result: 4096
    @Base = 4,
    @Exponent = 6

EXEC Exponentiation 10, 4 -- Result: 10000

EXEC Exponentiation 1000, -0.5 -- Result: 0.0316227766016838 (1 / √1000)