这就是我目前所拥有的:
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;
解决方法
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类型,以便您可以确定数据类型是正确的,这样如果表的数据类型发生更改,您将无需更改代码.