2017-06-13 54 views
0

嗨,我有3個觸發器,我無法編譯,我會appriciate一些幫助,因爲我不能解決它。 1)我在PL/SQL中有這張表 - 解決方案是這篇文章下的第一條評論!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語句,並我們可以看到有多少人在我們剛剛編輯的這個項目中工作。

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; 
/

我會真正appriciate我可以得到的所有幫助。謝謝!

+0

看起來像只是一個語法錯誤。 '選擇計數(PersonID)INTO peoplecount'。 –

+0

好吧,這對於第一個作品:D 謝謝 – QuietDaniel

回答

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