我有一个表Person包含字段是personName,personId,没有指定主要我在表中添加了一些值。 Person表中的值为Oracle序列没有生成
('muni',1)
('Ganesh',1)
我需要将主键添加为personId并将该列修改为自动生成。所以,我试图生成由以下查询序列生成触发作为
declare
id number;
begin
select max(rownum)+1 into id from Person;
execute immediate 'create sequence personseq start with '||to_char(id);
end;
如果当值表中的我执行上面的查询,然后将它正确地执行,但是当我有空表表示表中没有条目,则上述查询不会生成序列。
我也试过if语句。
declare
id number;
begin
select max(rownum)+1 into id from Person;
if (id=null) then
execute immediate 'create sequence personseq start with '||to_char(1);
else
execute immediate 'create sequence personseq start with '||to_char(id);
end if;
end;
系统说错误号是ORA01722
,它表示我给的号码无效号码。但我不知道错误在哪里?
任何帮助高度赞赏。
我已经在我的学校日阅读过这个概念,但我真的忘记了nvl。感谢提醒。 – MGPJ 2013-03-19 04:11:38
你能告诉我为什么If语句不工作 – MGPJ 2013-03-19 04:19:29
@muniganesh,检查更新的答案 – 2013-03-19 05:11:10