HSQLDB在TRIGGER中宣告行

时间:2012-09-21 10:15:21

标签: triggers hsqldb

大家好我尝试在触发器中从我的select语句中获取一行但是我得到了这个错误的意外令牌:R

         CREATE TRIGGER PUBLIC.TRIGGERNAME AFTER UPDATE ON     PUBLIC.CLIENTE_OFFERENTE 
             REFERENCING NEW ROW AS NUOVO 
                FOR EACH ROW 
                  BEGIN ATOMIC 
                   DECLARE r RECORD;
                   SET r=(SELECT offerta.IDIMMOBILE as ID, immobile.prezzomax as costo FROM PUBLIC.OFFERTA join immobile on immobile.idImmobile=offerta.idImmobile WHERE IDOFFERTA=NUOVO.IDOFFERTA);
                  IF NUOVO.STATO='Venduto'THEN 
                     INSERT INTO PUBLIC.VENDITE(IDCLIENTE,IDIMMOBILE,COSTO)VALUES(NUOVO.IDCLIENTE,r.ID,r.costo);
                   END IF;
                  END

1 个答案:

答案 0 :(得分:0)

您无法DECLARE RECORD类型的变量。

您希望从select语句中获取两个值。因此,您需要声明两个变量。

BEGIN ATOMIC 
    DECLARE VAR_ID INT;
    DECLARE VAR_COSTO INT;
    SET (VAR_ID, VAR_COSTO) =(SELECT offerta.IDIMMOBILE as ID, immobile.prezzomax as costo FROM PUBLIC.OFFERTA join immobile on immobile.idImmobile=offerta.idImmobile WHERE IDOFFERTA=NUOVO.IDOFFERTA);
    IF NUOVO.STATO='Venduto'THEN 
        INSERT INTO PUBLIC.VENDITE(IDCLIENTE,IDIMMOBILE,COSTO)VALUES(NUOVO.IDCLIENTE,VAR_ID,VAR_COSTO);
    END IF;
END