有两张表如下
JGS表
sjjgid   jgidJGYS表
sjjgid    jgid当JGS表中有记录写入的时候。
比如
insert into jgs(sjjgid,jgid)values(2,3)把这条记录同时写入JGYS表,并且
select sjjgid into tmp from jgys where jgid=2 (用jgs.sjjgid做为jgys.jgid来搜索jgys.sjjgid)
并把搜索出来的数据也写入jgys表中
insert into jgys(sjjgid,jgid) values(tmp,jgs.jgid)

解决方案 »

  1.   

    CREATE OR REPLACE TRIGGER XXX
      AFTER insert on JGS  for each row
    DECLARE
      pragma autonomous_transaction;
      tmp  number(20, 2);
    begin
      if inserting then
        begin
          select sjjgid into tmp from jgys where jgid=2
            insert into JGYS (sjjgid,jgid)
            values
              (:new.sjjgid,
               :new.jgid);
     insert into JGYS (sjjgid,jgid)
            values
              (tmp,
               :new.jgid); 
            commit;
          end if;
        end;
      end if;end;
      

  2.   

    select sjjgid into tmp from jgys where jgid=2记录条数不止一条的。是N条。N是未知数。
      

  3.   

    insert into JGYS (sjjgid,jgid) (select ......)
      

  4.   

    CREATE OR REPLACE TRIGGER abc
      AFTER insert on JGS  for each row
    DECLARE
      pragma autonomous_transaction;
      tmp  number(20, 2);
    begin
      if inserting then
        begin
          
            insert into JGYS (sjjgid,jgid)
            values
              (:new.sjjgid,
               :new.jgid);
     insert into JGYS (sjjgid,jgid)
            (select sjjgid,jgid from jgys where jgid=:new.sjjgid);====================
    这里有点问题。前面那个值是jgys表中搜索出来的。后面jgid要是:new.jgid这个值的。要怎么写
               commit;    end;
      end if;end;
      

  5.   

    已经搞定了。谢谢intotheheart()