我正在嘗試創建一個觸發器,其中需要來自稱爲FEEDBACK的表的多個評級,它會在MEMBER表上創建一個平均評級。我希望觸發器在每次插入新反饋時更新每個人的平均評分。平均評分觸發器ORACLE SQL
-----------這是我的表-----------
create table Member_T(
MemberID Varchar2 (10) primary key,
MemberFirstName Varchar2 (20) NOT NULL,
MemberLastName Varchar2 (20) NOT NULL,
MemberMidleName Varchar2 (10),
MemberEmail Varchar2 (50) NOT NULL,
MemberPassword Varchar2 (20) NOT NULL,
MemberAdress Varchar2 (50) ,
MemberCity Varchar2 (20) ,
MemberState char (2) ,
MemberCountry Varchar2 (20) ,
MemberZipCode number (5,0),
MemberPhone Varchar2 (12) ,
MemberAverageRating number (3,1) check (MemberAverageRating >= 0.0 AND MemberAverageRating <= 5.0));
create table Feedback_T(
FeedbackID Varchar2 (10) primary key,
FeedbackMemberGiverID Varchar2 (10) references Member_T(MemberID),
MemberReceiverID Varchar2 (10) references Member_T(MemberID),
MemberRating number (3,1) check (MemberRating >= 0.0 AND MemberRating <= 5.0),
MemberComment Varchar2 (500),
MemberFeedbackDate Date Default(sysdate));
---------- - 這是我的觸發-----------
create or replace trigger updateRating
after insert
on Feedback_T
for each row
Declare
rating Feedback_T.MemberRating%type;
receiver Feedback_T.MEMBERRECEIVERID%type;
averageRating Member_T.MemberAverageRating%type;
begin
select AVG(MemberRating), count(MEMBERRECEIVERID)
into rating, receiver
from Feedback_T
where Feedback_T.FEEDBACKID = :new.FEEDBACKID;
update Member_T
set averageRating = rating/receiver
where Member_T.MemberID = :new.MemberID;
end;
-----------我得到這個錯誤---------- -
TRIGGER UPDATERATING compiled
Errors: check compiler log
你用什麼客戶來編譯這個? – OldProgrammer
這是做家庭作業嗎?或者爲一個真正的系統?一旦你糾正了編譯錯誤,你幾乎肯定會得到變異的表運行時異常。它不會在多用戶系統中工作。在一個使用觸發器的真實系統中實現這種事情是可能的,但它比你在這裏得到的要複雜得多。 –
這是我一直在爲自己而努力的東西。我正在嘗試創建我的第一個觸發器,並且我想使用平均評分數據來完成此操作。我仍然不明白我在哪裏得到這個編譯錯誤。我正在使用ORACLE SQL Developer,而且我很難找到編譯器日誌... – user01230