0

Hi all I try to get a row form my select statemnt in a trigger but I got this error unexpected token: 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
4

1 回答 1

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
于 2012-09-21T13:40:17.137 回答