sql错误触发而不是

时间:2017-12-10 18:22:25

标签: oracle plsql database-trigger

我正在尝试创建一个而不是触发器,但我一直收到此错误:第11行出错:PL / SQL:忽略SQL语句

这是我的代码:

CREATE VIEW BiletNouVIP AS
SELECT nume, nrbilet, sursa, destinatia, clasa, valoare
FROM Clienti c, Bilete b
WHERE b.idclient = c.idclient AND c.statut = 'VIP';
  • nume来自Clienti
  • nrbilet,sursa,destinatia,clasa,valoare来自Bilete

唯一的主键是nrbilet

CREATE OR REPLACE TRIGGER new_BiletNouVIP
  INSTEAD OF INSERT ON BiletNouVIP FOR EACH ROW
DECLARE
  rowcnt integer := 0;
BEGIN
  INSERT INTO Clienti(nume)
  VALUES(:new.nume);
  SELECT COUNT(*) INTO rowcnt FROM Bilete WHERE nrbilet = :new.nrbilet;
  IF rowcnt = 0 THEN    
    INSERT INTO Bilete(nrbilet, clasa, valoare, sursa, destinatia)
    VALUES (:new.nrbilet, :new.clasa, :new.valoare, :new.sursa, :new.destinatia);
  ELSE
    UPDATE Bilete
    SET Bilete.clasa =: new.clasa, Bilete.valoare =: new.valoare, Bilete.sursa =: new.sursa, Bilete.destinatia =: new.destinatia
    WHERE Bilete.nrbilet =: new.nrbilet;
  END IF;
END;`

1 个答案:

答案 0 :(得分:1)

在ELSE分支中,您的赋值在冒号后面有一个空格 - =: new,这是无效的语法。冒号需要成为:new命名空间的一部分,如此

UPDATE Bilete
    SET Bilete.clasa = :new.clasa, 
        Bilete.valoare = :new.valoare, 
        Bilete.sursa = :new.sursa, 
        Bilete.destinatia = :new.destinatia
WHERE Bilete.nrbilet = :new.nrbilet