简体   繁体   中英

audit trigger in oracle12c is compiling with error

refer my ER

CREATE OR REPLACE TRIGGER EVA 
    AFTER INSERT ON C_EVALUATION
    FOR EACH ROW
    DECLARE
    v_cid number(25);
    v_isbn number(25);
    v_cname VARCHAR2(50);
    v_tittle VARCHAR2(150);
    v_date date;
    v_location VARCHAR2(50);
    v_eva VARCHAR2(250);
    BEGIN
    v_cid:=:OLD.C_ID;
    v_isbn:=:OLD.B_ISBN;
    v_eva:=:OLD.e_desc;

    SELECT C_NAME INTO v_cname FROM C_CUSTOMER WHERE C_ID = v_cid;
    select l_date INTO v_date FROM C_LEND where c_id = v_cid;
    select B_TITTLE INTO v_tittle FROM C_BOOK WHERE B_ISBN = v_isbn;
    SELECT TOWN INTO v_location FROM COPY WHERE B_ISBN = v_isbn;

    IF :NEW.R_ID IS NULL 
    THEN       
        INSERT INTO e_audit (
        c_name,
        b_tittle,
        h_date,
        location,
        evaluation
    ) VALUES (
        v_cname,
        v_tittle,
        v_date,
        v_location,
        v_eva
    );
    END IF;
    END;
    /

in the book table evaluation is given, but the evaluation,rate should be given by the customer, if the customer gives the rate as null value the below trigger should work. But we are getting an error saying as statement ignored, table or view does not exist. I checked it twice or more than that but all the table name and ID are perfect. please give us the solution to sort out the error

Something else looks wrong here. This is an INSERT trigger, but you are referring to :OLD.e_desc. This is wrong. An INSERT trigger should only refer to :NEW. A DELETE trigger should only refer to :OLD, whilst an UPDATE trigger can refer to both :NEW and :OLD. :OLD gives the value of the record before the change, but for INSERT there was no such record. I think what you really want is to use :NEW.e_desc, :NEW.c_id and :NEW.b_isbn. But I am guessing a little!

EDIT

Your diagram does not show all the fields? But what I think you need is:

SELECT TOWN into v_location FROM copy inner join lend 
ON lend.copyid = copy.copyid WHERE b_isbn = v_isbn 
AND lend.c_id = v_cid

What I am assuming here is that lend has a field copyid linking to copy.copyid and that it has a field linking to customer id. I am also assuming that copy has a field linking to b_isbn in book. According to your diagram, this must all be true, it is just that I do not know the field names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM