DB2在case块中抛出异常

nzk0hqpo  于 2023-01-20  发布在  DB2
关注(0)|答案(1)|浏览(201)

在我的触发器中,我想抛出一个异常,但它不能正常工作,得到了异常。

{0:0} An unexpected token "SQLSTATE '1234'" was found following "
        SIGNAL".  Expected tokens may include:  "<space>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.28.11

CREATE OR REPLACE TRIGGER "TRG_ABC_DELETE_CHECK"
 NO CASCADE BEFORE DELETE ON ABC
REFERENCING OLD AS OLD_OBJ
FOR EACH ROW MODE DB2SQL
BEGIN
    SELECT CASE WHEN (SELECT 1 FROM ABC WHERE ID = 2 OR NAME = 'AA' AND OLD_OBJ.TYPE = 2) THEN
        SIGNAL SQLSTATE '1234' ('Wrong Parameters');
    END FROM SYSIBM.SYSDUMM1;
END
ikfrs5lh

ikfrs5lh1#

不能在SELECT语句中使用其他语句(如SIGNAL)。
请改用RAISE_ERROR函数使SELECT有条件地引发异常。
或者使用CASE statement代替您在问题中使用的CASE expression

相关问题