求自增列在插入什么如何操作?SQL语句怎么写的?

解决方案 »

  1.   

    insert into t (your_seq.next_val, ....)
      

  2.   

    提示:your_seq.next_val,这个是your_seq是一个数列,你要先行定义。your_seq.next_val是调用的方法
      

  3.   

    如果要自动插入自增列的话可以使用一个触发器来实现。
    其中使用:
    :new.id:=id_seq.next_val; --id_seq为序列名称。
      

  4.   

    --创建序列
    create sequence sqe1
    start with 1
    increment by 1
    maxvalue 9999999
    nocycle
    --用触发器实现自动插入自增的列(这里id 为你的自增列)
    create or replace tigger tri_tb before insert on tb for each row
    declare
    v_id tb.id%type;
    begin
    select sqe1.nextval into v_id from dual;
    :new.id:=v_id;
    end;
      

  5.   


    create sequen sqe1
    start with 1
    increment by 1insert into tb(sqe1.nextval,.....)--也可以用触发器create or replace trigger p_incre before insert on tb for each row
    declare
    v_id tb.id%type;
    begin
    select sqe1.nextval into v_id from dual;
    :new.id:=v_id;
    end;
      

  6.   

    定义触发器之后,sql语句插入数据时直接把这个字段空着就行,相当于有一个默认值
      

  7.   

    能过sequence 来实现处增.
    创建sequence
    create sequence autoinc
    minvalue 1
    start with 1
    increment by 1
    nocycle
    cache 10;
    使用
    insert into table_name values (autoinc.nextval,........)