oracle插入主键数据、sequence和触发器

  一、创建表:

     id number;并设为主键

    name VARCHAR2(20 BYTE)

  二、

    插入数据

    2.1  insert into addservice.test_table (id,name)values('1','testMR');

    2.2  创建sequence后插入数据:

        

create sequence test_sequence
increment by 1
start with 100
nomaxvalue
nocycle
nocache

      insert into test_table (id,name)values(test_sequence.nextval,'testSequence');

    2.3  创建触发器后插入数据:

      

create or replace trigger test_id_trigger
before insert on test_table for each row
declare
nextid number;
begin
if :new.id is null
then
select test_sequence.nextval into nextid from dual;
:new.id := nextid;
end if;
end test_id_trigger;

      insert into test_table(id,name)values(null,'testTriggerNull');

      insert into test_table(name)values('testTrigger');

  三、查看数据:

      select * from test_table;

  oracle插入主键数据、sequence和触发器

上一篇:HTML5 Canvas 绘制时钟


下一篇:C# 之 未能映射路径