2016-10-11 60 views
-2

我想創建一個觸發器,用於在Oracle中自動增加id值。下面是我試過用爲什麼我在Oracle中遇到文件的符號結尾?

create or replace 
trigger themes_on_insert 
before insert on THEME 
for each row 
begin 
select themes_sequence.nextval 
into :new.ID 
from dummy 
end; 

錯誤(5,4)的代碼:PLS-00103:出現符號「檔案結尾」在需要下列之一時:(開始案件宣告結束退出異常的轉到如果環模空編譯提高收益選擇更新而與< <繼續關閉當前刪除獲取鎖芯打開回滾保存點設置SQL執行提交FORALL合流管清洗

回答

2

語句必須以結束;並且整個PL/SQL塊必須以結尾

create or replace trigger themes_on_insert 
    before insert on THEME 
    for each row 
begin 
    select themes_sequence.nextval 
    into :new.ID 
    from dummy; --<< missing ; here 
end; 
/

select實際上是沒有必要的,這可以簡化爲:

create or replace trigger themes_on_insert 
    before insert on THEME 
    for each row 
begin 
    :new.ID := themes_sequence.nextval; 
end; 
/

要詳細瞭解爲什麼/需要看到here

0

;從假人失蹤後?

create or replace 
trigger themes_on_insert 
before insert on THEME 
for each row 
begin 
select themes_sequence.nextval 
into :new.ID 
from dummy; 
end; 
相關問題