Oracle触发器

1、创建序列


create sequence seq_whn increment by 1 start with 1 maxvalue 2147483647 nocycle cache 10;


create sequence seq_whr increment by 1 start with 1 maxvalue 2147483647 nocycle cache 10;

 


2、创建触发器


whn表node_id自动增长


create or replace
trigger trigger_whn before
  insert on whn for each row declare node_id number;
  begin
    select seq_whn.nextval into node_id from dual;
   
    :new.node_id:=node_id;
  end;

 

whr表node_id自动增长


create or replace
trigger trigger_whr before
  insert on whr for each row declare link_id number;
  begin
    select seq_whr.nextval into link_id from dual;
   
    :new.link_id:=link_id;
  end;

 

更新whr表中的start_node_id,end_node_id


create or replace
TRIGGER TRIGGER_RN AFTER
  INSERT ON WHR BEGIN
  update whr
  set start_node_id=
    (select id from whn where whn.id=whr.snodeid
    ),
    end_node_id=
    (select id from whn where whn.id=whr.enodeid
    );
 
  NULL;
END;

你可能感兴趣的:(oracle,cache)