oracle創建序列以及時間戳的使用

CREATE SEQUENCE emp_sequence -- emp_sequence這個就是後面要用到這個序列號時引用的名稱
INCREMENT BY 1  -- 每次加幾個
START WITH 1   -- 從1開始計數
NOMAXVALUE    -- 不設置最大值
NOCYCLE     -- 一直累加,不循環

CACHE 100; -- 緩存值 100



create sequence S_TB_STUDENT
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;



oracle如何設置序列自動增長

 
droptable book;  
--創建表    
createtable book(      
  bookId varchar2(4) primarykey,  
  name varchar2(20)        
);  
--創建序列    
createsequence book_seq start with 1 increment by 1;  
 
--創建觸發器    
createorreplacetrigger book_trigger      
before inserton book      
for each row      
begin      
select book_seq.nextval into :new.bookId from dual;    
end ;  
--添加數據    
insertinto book(name)  values ('cc');  
insertinto book(name)  values ('dd');  
 
commit; 


create or replace trigger mytable_trig_autoinc
before insert on mid_org_orgs
for each row
begin
  if (:new.mid_id is null) then
    select mid_id.nextval into :new.mid_id from dual;
  end if;
end;





CHAR(19) default to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章