一、创建表:

     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和触发器

 

相关文章:

  • 2022-03-14
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2022-02-03
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案