每次插入时用下面的语句取一个最大留言号就可以阿
select max(liuyan_id) +1 where c_no='班级'

解决方案 »

  1.   

    如果是多人操作的话,使用max(liuyan_id) +1会有问题,还是建议使用ORACLE的序列(sequence)
    1.创建序列:
    create sequence your_seq
    nocycle
    maxvalue 9999999999
    start with 1;使用触发器实现自增:
    create or replace trigger your_seq_tri
    before insert on your_table1 for each row
    declare
      next_id number;
    begin
      select your_seq.nextval into next_id from dual;
      :new.id := next_id;
    end;
      

  2.   

    "happya3000(清凉油)"你好!可以用触发器来实现,很简单的,如下:create or replace trigger liuyan_trigger
    before insert
    on liuyan
    for each row
    declare
    v_liuyan_id number;
    begin
      select max(liuyan_id) into v_liuyan_id from liuyan where c_no = :new.c_no;
      v_liuyan_id := v_liuyan_id + 1;
      select v_liuyan_id into :new.liuyan_id from dual;
    end;
    /
    Thanks
    Hima