简体   繁体   English

简单的触发错误?! PL/SQL:ORA-00933:

[英]Simple Trigger Error?! PL/SQL: ORA-00933:

I am attempting to create a trigger that will insert values into an audit table for approval by an admin user.我正在尝试创建一个触发器,它将值插入到审核表中以供管理员用户批准。 The trigger will insert new values that are added into a consultant table into this audit table.触发器会将添加到顾问表中的新值插入到此审计表中。

I have re-jigged the trigger a lot but cannot seem to bypass the compilation error!我已经多次重新触发触发器,但似乎无法绕过编译错误! I assume it's something small?我认为这是小事?

DROP TABLE   MyAuditTable;
CREATE TABLE MyAuditTable (
    audit_id INTEGER NOT NULL,
    new_name VARCHAR2 (30),
    new_postcode VARCHAR2 (20),
    status     VARCHAR2 (15), 
    CONSTRAINT pk_MyAuditTable  PRIMARY KEY ( audit_id )
); 


DROP sequence MySeq;
Create sequence MySeq MINVALUE 1 MAXVALUE 9999999 INCREMENT BY 1 START WITH 1;

drop trigger MyTrigger;
create trigger MyTrigger
after insert on my_consultant_table
for each row
begin
    insert into MyAuditTable values (
        MySeq.nextval, :new.con_name, 
        :new.con_postcode, 
        'Pending'
    )
    from my_consultant_table;
end;
/

ERROR: PL/SQL: ORA-00933:错误:PL/SQL:ORA-00933:

So the audit table should now have the newly inputted data from the consultant table, which contains name and postcode attributes.所以审计表现在应该有来自顾问表的新输入数据,其中包含姓名和邮政编码属性。 Another trigger will fire so that when the status is changed, these changes are permitted.另一个触发器将触发,以便在状态更改时允许这些更改。

Thank You!谢谢你!

The line线

from my_consultant_table

Is unnecessary.是不必要的。

Should be:应该:

insert into MyAuditTable values (MySeq.nextval, :new.con_name, :new.con_postcode, 'Pending');

This ORA-00933 denotes a syntax error in your trigger declaration :此 ORA-00933 表示触发器声明中存在语法错误:

begin
    insert into MyAuditTable values (
        MySeq.nextval, :new.con_name, 
        :new.con_postcode, 
        'Pending'
    )
    from my_consultant_table;
end;

The trailing from my_consultant_table does not make sense, just remove it and you should be fine : from my_consultant_table的尾随没有意义,只需将其删除即可:

begin
    insert into MyAuditTable values (
        MySeq.nextval, :new.con_name, 
        :new.con_postcode, 
        'Pending'
    );
end;

Try this:尝试这个:

begin
insert into MyAuditTable 
   select
    MySeq.nextval,
    :new.con_name, 
    :new.con_postcode, 
    'Pending'
   from dual;
end;

One Tip: When u create a sequence and always use from 1 to 9999999.... anc increment one by one.一个提示:当你创建一个序列时,总是使用从 1 到 9999999.... 一一递增。 Just use只需使用

create sequence owner.table nocache;

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

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