2017-08-02 129 views
1

我想在Oracle中創建觸發器像打擊創建:警告:觸發與編譯錯誤

CREATE OR REPLACE TRIGGER TRIGGER_VC_PART_LIST 
BEFORE INSERT ON VC_PART_LIST FOR EACH ROW 
BEGIN 
SELECT VC_PART_LIST_SEQ.NEWTVAL INTO :new.SEQ_ID FROM dual; 
END; 
/

任何人都可以幫我THX?

+0

使用'顯示errors' –

回答

-1

您的代碼中幾乎沒有問題。

1)VC_PART_LIST_SEQ.NEWTVAL在Oracle中沒有什麼叫做NEWTVAL。它應該是Nextval

2)不需要SQL聲明。

見演示:

觸發:

CREATE OR REPLACE TRIGGER TRIGGER_VC_PART_LIST 
    BEFORE INSERT 
    ON VC_PART_LIST 
    FOR EACH ROW 
BEGIN 
    :new.SEQ_ID := VC_PART_LIST_SEQ.NEXTVAL; 
END; 
/

表:

create table VC_PART_LIST (SEQ_ID number, 
VC_VTC varchar2(20), PART_NO varchar2(20), CONSUME_QTY varchar2(20)); 

序列

create sequence VC_PART_LIST_SEQ start with 1 increment by 1; 

插入:

INSERT INTO VC_PART_LIST (VC_VTC, PART_NO, CONSUME_QTY) 
    VALUES ('6175SMFGD132000D', 'SC25R136', '11'); 

Commit; 

選擇:

SQL> select * from VC_PART_LIST; 

    SEQ_ID VC_VTC    PART_NO    CONSUME_QTY 
---------- -------------------- -------------------- -------------------- 
     1 6175SMFGD132000D  SC25R136    11 
1

按順序取下一個值使用NEXTVAL。以下是正確的語法

CREATE OR REPLACE TRIGGER TRIGGER_VC_PART_LIST 
    BEFORE INSERT 
    ON VC_PART_LIST 
    FOR EACH ROW 
BEGIN 
    SELECT VC_PART_LIST_SEQ.NEXTVAL INTO :new.SEQ_ID FROM DUAL; 
END; 
+0

Thx.But當我inserte數據到表與另一個錯誤觸發 'OTDTEST.TRIGGER_VC_PART_LIST'插入sql是INSERT INTO VC_PART_LIST(VC_VTC,PART_NO,CONSUME_QTY)VALUES('6175SMFGD132000D','SC25R136','11'); –

+0

分享你的表格結構。 Consume_qty是一個數字還是varchar2類型的列? – Himanshujaggi