其中一个突变触发错误而不知道如何解决它。该函数计算给出的评论数量,触发器显示评论记录的数量:
CREATE OR REPLACE FUNCTION func_no_of_reviews_for_venue (in_venue_id reviews.venue_id%TYPE)
RETURN NUMBER IS
vn_no_of_reviews reviews.review_id%TYPE := 0;
BEGIN
SELECT COUNT(*)
INTO vn_no_of_reviews
FROM reviews;
RETURN vn_no_of_reviews;
END func_no_of_reviews_for_venue;
/
SHOW ERRORS;
-- trigger to get a venue's average rating when a new review has been added
CREATE OR REPLACE TRIGGER trig_get_venue_avg_rating
AFTER INSERT OR UPDATE OF rating ON reviews
FOR EACH ROW
WHEN (NEW.rating IS NOT NULL)
DECLARE
vn_no_reviews NUMBER(6);
vn_avg NUMBER(2,1);
BEGIN
vn_no_reviews := func_no_of_reviews_for_venue(:NEW.venue_id);
DBMS_OUTPUT.PUT_LINE ('Number of reviews: ' || vn_no_reviews);
END trig_age_ck;
/