获取sql错误,db2函数错误返回结果

时间:2017-12-01 23:48:49

标签: sql database db2 sql-function

我的功能出错,但我不知道为什么......

我的(DB2)SQL代码:

CREATE FUNCTION gibX(sseries INTEGER, idd INTEGER) RETURNS Double
 BEGIN
   Declare result Double;
   SELECT ROW_NUMBER() OVER(ORDER BY m.x ASC) AS Row, m.x  INTO result 
   FROM messungen m WHERE m.series=sseries and Row=idd;
   return result;
 END;

ERROR:

CREATE FUNCTION;
   return result;
;, DRIVER=4.13.80

...并顺利通过。

1 个答案:

答案 0 :(得分:1)

您无法在row中引用where。一种方法是子查询:

SELECT x INTO result
FROM (SELECT ROW_NUMBER() OVER (ORDER BY m.x ASC) AS Row, m.x  
      FROM messungen m
      WHERE m.series = sseries
     ) m
WHERE Row = idd;