Trigger and Sequence实现采番的区别

1. Sequence的创建:
Create SEQUENCE SEQUENCE名称   
MINVALUE 1   
MAXVALUE 999999999
Start With 1   
INCREMENT By 1   
CACHE 20;   


2.Trigger的创建:
Create or Replace Trigger 触发器名   
    Before Insert On 表   
    For Each Row;
CURSOR cur_tri_id AS
    Select SEQUENCE名称.Nextval Into :New.表的自增字段名 From DUAL; 
i number; 
Begin  
    OPEN cur_tri_id;
    FOR TRI_ID IN cur_tri_id Loop
       if Tri_id is null then
	 i := 0;
       Else
         i := i+1;

       End IF;
    END LOOP;
    CLOSE CUR_TRI_ID;
End;

所以一般来说,采用Sequence比Trigger在性能要好。。

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