小编典典

多次插入相同的数据

sql

我有一个类似于以下内容的插入语句:

insert into table (id, name, descr) values (4, 'asdf', 'this is not a word');

我需要使用多个ID插入同一条语句。现在我有:

insert into table (id, name, descr) values (4, 'asdf', 'this is not a word');
insert into table (id, name, descr) values (6, 'asdf', 'this is not a word');
insert into table (id, name, descr) values (7, 'asdf', 'this is not a word');
insert into table (id, name, descr) values (9, 'asdf', 'this is not a word');

我只是必须运行此程序,还是有一个更精简的版本?


阅读 198

收藏
2021-04-22

共1个答案

小编典典

使用select . . . insert

insert into table(id, name, descr) 
    select i.id, 'asdf', 'this is not a word'
    from (select 4 as id from dual union all
          select 6 from dual union all
          select 7 from dual union all
          select 9 from dual
         ) i;
2021-04-22