建一个触发器CREATE OR REPLACE TRIGGER TRIG_AMETER_ARCH_ZZBH
  BEFORE INSERT ON TAMETER_RT_ARCHIVE  
  FOR EACH ROW
DECLARE
  -- local variables here
 -- record_count integer;
 /******************************************************************************
   PURPOSE:   电表运行数据存档自动编号   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2003-10-17   Fred Zhang       1. Created this procedure.
******************************************************************************/
BEGIN
      --select count(ZZBH) into record_count from Tameter_Rt_archive;
      --if record_count=0 then 
       --  :new.ZZBH:=1;
     -- else
         SELECT SEQ_DB_RT_ARCH.NEXTVAL INTO :NEW.ZZBH FROM dual;
     -- end if;
END TRIG_AMETER_ARCH_ZZBH;
/

解决方案 »

  1.   

    他不能像mssql那樣
    只設一下字段的datatype就行嗎,怎麼那麼麻煩的.
      

  2.   

    create table a
    (b int,
     c  varchar2(5));create sequence a_seq increment by 1 start with 100;create or replace trigger t_a
    before insert on a
    for each row
    begin
         select s_a.nextval into :new.b from dual;
    end;
      

  3.   

    先建序列.然后执行插入,
    create sequence a_seq increment by 1 start with 100;
    insert into tablea values(a_seq.nextval,...)  --就会自动加1了,
      

  4.   

    請問a_seq 代表什麼我現在的表名是users
    這段1是id,number 型
    如果設成自增