2015-11-02 54 views
0

的問題是關於使用序列上線4Oracle列不允許在這裏默認值

CREATE OR REPLACE SEQUENCE CHANNEL_SEQ START WITH 1 INCREMENT BY 1; 

    CREATE TABLE "CHANNEL" ( 
    "ID_CHANNEL" NUMBER(18,0) DEFAULT CHANNEL_SEQ.NEXTVAL, 
    "IS_ACTIVE" VARCHAR2(1 CHAR) NOT NULL, 
    "BATCH_SIZE" NUMBER(3,0) NOT NULL, 
    "MAX_DOCS_IN_PROCESS" NUMBER(4,0) NOT NULL, 
    "RECEIVER_ID" NUMBER(18,0) NOT NULL, 
    "LAST_POS_SESSION_TIME" DATE, 
    CONSTRAINT "PK_CHANNEL" PRIMARY KEY ("ID_CHANNEL"), 
    CONSTRAINT "FK_RECEIVER_ID_CHANNEL" FOREIGN KEY ("RECEIVER_ID") REFERENCES "MSG_OUT"("MSG_OUT_ID"), 
    CONSTRAINT "CHK_IS_ACTIVE" CHECK (IS_ACTIVE IN ('Y', 'N')) 
    ); 

錯誤消息的默認值是:

"SQL Error: ORA-00984: column not allowed here"

所有幫助和提示的歡迎。

+0

? – Boneist

回答

2

您不能使用seq.NEXTVAL作爲默認值。

爲此(自動填充),你應該創建觸發器,像

CREATE OT REPLACE TRIGGER 
BEFORE INSERT 
ON CHANNEL 
FOR EACH ROW 
BEGIN 
:NEW.ID_CHANNEL:=CHANNEL_SEQ.NEXTVAL; 
END; 
您正在使用哪個Oracle版本