平均评级触发器ORACLE SQL

时间:2014-04-09 23:40:09

标签: sql oracle

我正在尝试创建一个触发器,其中从一个名为FEEDBACK的表中获取几个等级,并在MEMBER表上创建一个平均等级。我希望触发器在插入新反馈时更新每个人的平均评分。

-----------这些是我的表-----------

 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

1 个答案:

答案 0 :(得分:0)

如果您运行&#34;显示错误&#34;从SQL提示符,您将看到您的错误,或在SQLDeveloper中编译它,它将显示错误。你的问题是:

where Member_T.MemberID = :new.MemberID;

没有名为new.MemberID的绑定变量,因为MemberID不是触发器所针对的Feedback_T表中的列。也许您打算引用FeedbackMemberGiverID或MemberReceiverID?