这就是我目前拥有的:
CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON SOMETABLE FOR EACH ROW DECLARE v_emplid varchar2(10); BEGIN SELECT personnum into v_emplid FROM PERSON WHERE PERSONID = :new.EMPLOYEEID; dbms_output.put(v_emplid); /* INSERT INTO SOMEOTHERTABLE USING v_emplid and some of the other values from the trigger table*/ END MYTRIGGER;
DBA_ERRORS有此错误:PL/SQL:ORA-00923:未找到FROM关键字
1)你的例子必须有其他东西,因为这肯定对我有用
SQL> create table someTable( employeeid number ); Table created. SQL> create table person( personid number, personnum varchar2(10) ); Table created. SQL> ed Wrote file afiedt.buf 1 CREATE OR REPLACE TRIGGER MYTRIGGER 2 AFTER INSERT ON SOMETABLE 3 FOR EACH ROW 4 DECLARE 5 v_emplid varchar2(10); 6 BEGIN 7 SELECT personnum 8 into v_emplid 9 FROM PERSON 10 WHERE PERSONID = :new.EMPLOYEEID; 11 dbms_output.put(v_emplid); 12 /* INSERT INTO SOMEOTHERTABLE USING v_emplid and some of the other values from the trigger table*/ 13* END MYTRIGGER; 14 / Trigger created. SQL> insert into person values( 1, '123' ); 1 row created. SQL> insert into sometable values( 1 ); 1 row created.
2)您可能希望将V_EMPLID声明为Person.PersonNum%TYPE类型,以便您可以确定数据类型是正确的,这样如果表的数据类型发生更改,您将无需更改代码.
3)我假设您知道您的触发器无法查询或更新定义了触发器的表(因此不会对someTable进行查询或插入).