简体   繁体   English

oracle12c中的审计触发器正在错误编译

[英]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. 我检查了两次或更多次,但所有表名和ID都很完美。 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. 这是一个INSERT触发器,但是您指的是:OLD.e_desc。 This is wrong. 错了 An INSERT trigger should only refer to :NEW. INSERT触发器应仅引用:NEW。 A DELETE trigger should only refer to :OLD, whilst an UPDATE trigger can refer to both :NEW and :OLD. DELETE触发器应仅引用:OLD,而UPDATE触发器可以同时引用:NEW和:OLD。 :OLD gives the value of the record before the change, but for INSERT there was no such record. :OLD给出更改前记录的值,但是对于INSERT,没有这样的记录。 I think what you really want is to use :NEW.e_desc, :NEW.c_id and :NEW.b_isbn. 我认为您真正想要的是使用:NEW.e_desc,:NEW.c_id和: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. 我在这里假设的是,借贷具有链接到copy.copyid的字段copyid,并且具有链接到客户ID的字段。 I am also assuming that copy has a field linking to b_isbn in book. 我还假设该副本具有链接到书中的b_isbn的字段。 According to your diagram, this must all be true, it is just that I do not know the field names. 根据您的图表,这必须全部正确,只是我不知道字段名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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