我有一個表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