【发布时间】:2014-12-26 12:36:20
【问题描述】:
我在一次向表中插入多行时遇到问题,因为列 id 具有主键并且它是基于序列创建的。
例如:
create table test (
iD number primary key,
name varchar2(10)
);
insert into test values (123, 'xxx');
insert into test values (124, 'yyy');
insert into test values (125, 'xxx');
insert into test values (126, 'xxx');
以下语句会导致违反约束的错误:
insert into test
(
select (SELECT MAX (id) + 1 FROM test) as id,
name from test
where name='xxx'
);
此查询应在表 test 中插入 3 行(name=xxx)。
【问题讨论】:
标签: oracle