缺少括号

时间:2010-08-05 14:50:14

标签: oracle plsql triggers

这是我正在运行的脚本

DROP SEQUENCE S_JobStatus;

CREATE SEQUENCE S_JobStatus
    INCREMENT BY 1
    START WITH 1
    NOMAXVALUE 
    NOMINVALUE 
;
-- 
-- TABLE: JobStatus 
--

DROP TABLE JobStatus;
CREATE TABLE JobStatus(
    Id             NUMBER(10, 0)    NOT NULL,
    ShortName      NUMBER(10, 0)    NOT NULL,
    Description    NUMBER(10, 0)    NOT NULL,
    CONSTRAINT PK_JobStatus PRIMARY KEY (Id)
)
;
/* DROP TRIGGER JobStatus_SequenceTrigger; */
CREATE TRIGGER JobStatus_SequenceTrigger
BEFORE INSERT
ON JobStatus
    FOR EACH ROW
    WHEN new.Id IS NULL
    BEGIN
        SELECT S_JobStatus.nextval into :new.Id from dual
    END;

以下是Oracle SQL Developer中的输出

DROP SEQUENCE S_JobStatus succeeded.
CREATE SEQUENCE succeeded.
DROP TABLE JobStatus succeeded.
CREATE TABLE succeeded.

Error starting at line 22 in command:
CREATE TRIGGER JobStatus_SequenceTrigger
BEFORE INSERT
ON JobStatus
    FOR EACH ROW
    WHEN new.Id IS NULL
    BEGIN
        SELECT S_JobStatus.nextval into :new.Id from dual
    END;
Error report:
ORA-00906: missing left parenthesis
00906. 00000 -  "missing left parenthesis"
*Cause:    
*Action:

我在哪里错过了括号?

1 个答案:

答案 0 :(得分:11)

我认为您的触发条件需要括号。

WHEN (new.Id IS NULL)

创建触发器语法:

http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/statements_7004.htm