现在有两个表,主细关系。现在要在细表上写触发器,然后用主表id得到这个id在细表中所有字段内容,然后在添加到主表的一个字段中,现在不知怎么写了。请大家帮忙!!!!

解决方案 »

  1.   

    用主表id得到这个id在细表中所有字段内容
    怎么得到主表ID?
    应该在主表上写触发器吧
      

  2.   

    同步主表和明细表吧
    应该分2种操作:若id在主表中已存在,则更新,若不存在,则增加create or replace trigger tgname
    after insert on tabname
    for each row
    declare
    v_count number;
    begin
    select count(1) into v_count from 主表 where id=:new.id;
    if v_count=0 then
    insert into 主表 values (:new.id,:new....);
    else
    update 主表 set 数量=数量+:new.数量 where id=:new.id;
    end if;
    end;