2010-01-24 110 views
1

我試圖創建一個觸發器,從預定義的序列設置ID。創建插入觸發器錯誤

CREATE SEQUENCE seq_list_status 
    START WITH 1 
    INCREMENT BY 1 

; 

CREATE OR REPLACE TRIGGER trg_list_status_insert 
    BEFORE INSERT ON list_status 
    FOR EACH ROW 
    select seq_list_status.nextval into :new.id from dual; 
/

我得到下面的錯誤在創建觸發器

Error starting at line 1 in command: 
CREATE OR REPLACE TRIGGER trg_list_status_insert 
    BEFORE INSERT ON list_status 
    FOR EACH ROW 
    select seq_list_status.nextval into :new.id from dual 
Error at Command Line:4 Column:4 
Error report: 
SQL Error: ORA-04079: invalid trigger specification 
04079. 00000 - "invalid trigger specification" 
*Cause: The create TRIGGER statement is invalid. 
*Action: Check the statement for correct syntax. 

我GOOGLE了它,但它似乎一切OK。任何想法可能是錯誤的?

回答

5

你缺少的beginend

CREATE OR REPLACE TRIGGER trg_list_status_insert 
BEFORE INSERT ON list_status 
FOR EACH ROW 
BEGIN 
select seq_list_status.nextval into :new.id from dual; 
END; 
/
6

觸發器是程序單元。因此,我們必須將代碼體包裝在BEGIN和END中。試試這個

CREATE OR REPLACE TRIGGER trg_list_status_insert 
    BEFORE INSERT ON list_status 
    FOR EACH ROW 
BEGIN 
    select seq_list_status.nextval into :new.id from dual; 
END; 
/

不幸的是the examples in the SQL Reference沒有我們想的那麼有幫助。但它鏈接到其他有用的文檔,如the App Developers Guide