现在要插入一个值,如果为空则插入0,非空则插入最大的值加1
形式是这样的
insert into t1(id) values ()
插号内就是要插入的ID,若表为空则ID插入0,不为空则插入ID的最大值加1
ID为主键

解决方案 »

  1.   

    declare
      i number;
      is_id number;
    begin
    select count(*) into i
    from   your_table;if i = 0 then 
      is_id := 0
    else
      select max(id) into is_id
      from   your_table ;
      is_id := is_id +1;
    end if ;
    insert into your_table (id) values (is_id);
    commit;
    end;
      

  2.   

    没办法,只有建个序列,用nextval来解决了,谢谢包子,分都给你