我有一个类似于这样的插入语句:

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');

我只需要运行它,还是有更精简的版本?

最佳答案

使用 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;

10-07 16:10
查看更多