1

THEN当子句中使用 UDF 时,子句代码中会发生错误WHEN,尽管函数返回 false。

-- a simple function for example
CREATE FUNCTION "is_one"
( 
      IN checkNum INTEGER
)
RETURNS is_one INTEGER
LANGUAGE SQLSCRIPT
AS
BEGIN
    IF 
        :checkNum = 1
    THEN 
        is_one := 1;
    ELSE 
        is_one := 0;
    END IF;
END;

SELECT "is_one"(1) FROM DUMMY; -- returns 1
SELECT "is_one"(0) FROM DUMMY; -- returns 0

-- error...  [304]: division by zero undefined: cannot be divided by zero at function /()
SELECT
    CASE
        WHEN "is_one"(0) = 1 THEN 1/0
        ELSE 0
    END AS x 
FROM DUMMY;

-- an error does not occur if the function is not used
-- returns 0
SELECT
    CASE
        WHEN 0 = 1 THEN 1/0
        ELSE 0
    END AS x 
FROM DUMMY;

我希望输出为 0,但实际我得到一个错误。

4

1 回答 1

0

刚刚尝试使用 SAP HANA 2.40 重新创建它,但我没有收到错误,但预期值为 0

于 2019-11-07T05:06:24.743 回答