oracle insert 查询出来的结果批量插入一个表 【oracle一次插入多条数据(insert all)】

1 插入语句包含主键

create sequence seq_test_insert 
minvalue 1
maxvalue 999999999999999999999999
start with 1
increment by 1
cache 20;
INSERT INTO table1 (SID, field1, field2 )

SELECT seq_test_insert.nextval,  t2.field1, t2.field2  FROM table1 t2

2 插入语句没有主键,添加触发器

--创建表的触发器(用来触发id自增)
--DROP SEQUENCE test_seq;

create sequence test_seq start with -1 increment by -1;

--创建表的触发器(用来触发id自增)
--drop trigger test_trigger ;

create or replace trigger test_trigger 
before insert or update on table
for each row
  when (new.sid is null)
begin
  select test_seq.nextval into :new.sid from dual;
end;

 然后再执行插入语句

这里没有主键

insert into table (field1,field2) values (val1, val2);

转载地址:

oracle一次插入多条数据(insert all)_gnail_oug的博客-CSDN博客_oracle添加多行数据

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值