PL / SQL中没有工作变量

时间:2017-06-13 16:15:14

标签: plsql plsqldeveloper

嗨我有3个触发器我无法编译,我会赞美一些帮助,因为我无法绕过它。 1)我在PL / SQL中有这个表 - 解决方案是这篇文章下的第一个评论!

CREATE TABLE Personel_Project (
    ProjectID INT,
    PersonID INT,
    FOREIGN KEY (ProjectID) REFERENCES Project(ProjectID),
    FOREIGN KEY (PersonID) REFERENCES Personel(PersonID)
);/

这个触发器不起作用,我几乎可以肯定它与名称声明有关。

CREATE OR REPLACE TRIGGER peopleInProjects 
AFTER DELETE OR INSERT OR UPDATE ON Personel_Project 
FOR EACH ROW 
DECLARE
projectnumber NUMBER := :new.ProjectID;
peoplecount NUMBER;
BEGIN 
    Select INTO peoplecount Count(PersonID) FROM Personel_Project Group by projectnumber;
    dbms_output.put_line('ID of project: ' || projectnumber); 
    dbms_output.put_line('number of people working in this project: ' || peoplecount); 
END; 
/ 

我收到此错误 错误(4,5):PL / SQL:忽略SQL语句

这个触发器背后的想法是当有人在DB中编辑这个表时启动它,我们可以看到有多少人在我们刚刚编辑的这个项目中工作。

2)

CREATE TABLE Project (
    ProjectID INT PRIMARY KEY,
    Name VARCHAR(255),
    Due_date DATE,
    Cost INT,
    Payout INT
);

使用此表时,当我尝试通过以下方式调用表中的更改时出现错误:new.DUE_DATE,现在我正在使用:DUE_DATE。无法继续前进

CREATE OR REPLACE TRIGGER showChange
  BEFORE
    INSERT OR
    UPDATE OF DUE_DATE, COST, PAYOUT OR
    DELETE
  ON PROJECT
BEGIN
  CASE
    WHEN INSERTING THEN
      DBMS_OUTPUT.PUT_LINE('you put in this information' || :DUE_DATE || :COST || :PAYOUT );
    WHEN UPDATING('Due_date') THEN
      DBMS_OUTPUT.PUT_LINE('you updated due date to be' || :DUE_DATE );
    WHEN UPDATING('Cost') THEN
      DBMS_OUTPUT.PUT_LINE('you updated cost to be' || :COST );
    WHEN UPDATING('Payout') THEN
      DBMS_OUTPUT.PUT_LINE('you updated Payout to be' || :PAYOUT );
    WHEN DELETING THEN
      DBMS_OUTPUT.PUT_LINE('You deleted the project');
  END CASE;
END;
/

我真的很高兴能得到所有帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

在此触发器中:

CREATE OR REPLACE TRIGGER peopleInProjects 
AFTER DELETE OR INSERT OR UPDATE ON Personel_Project 
FOR EACH ROW 
DECLARE
projectnumber NUMBER := :new.ProjectID;
peoplecount NUMBER;
BEGIN 
    Select INTO peoplecount Count(PersonID) FROM Personel_Project Group by projectnumber;
    dbms_output.put_line('ID of project: ' || projectnumber); 
    dbms_output.put_line('number of people working in this project: ' || peoplecount); 
END; 
/ 

Select INTO peoplecount Count(PersonID) FROM...这不是select <column1>, <column2>, ... INTO <variable1>, <variable2>, ...

的方法

Oracle DB SELECT INTO