2010-08-09 111 views
1

我有一個腳本來創建表和相關結構SHOW錯誤終止執行

DROP TABLE CDR.ExtDL_JobStatus; 

-- 
-- TABLE: CDR.ExtDL_JobStatus 
-- 

CREATE TABLE CDR.ExtDL_JobStatus(
    Id    NUMBER(38, 0) NOT NULL, 
    ShortName  NUMBER(38, 0) NOT NULL, 
    Description NUMBER(38, 0) NOT NULL, 
    CONSTRAINT PK_ExtDL_JobStatus PRIMARY KEY (Id) 
) 
; 



SHOW ERRORS; 
Declare NumOfSequences NUMBER :=0; 
Begin 
    Select COUNT(*) 
    INTO NumOfSequences 
    FROM All_Sequences 
    WHERE 1=1 
    And upper (Sequence_Owner) = upper ('CDR') 
    And upper (Sequence_Name) = upper ('ExtDL_JobStatus_Seq'); 
    If NumOfSequences > 0 Then 
    Execute IMMEDIATE 'DROP SEQUENCE CDR.ExtDL_JobStatus_Seq'; 
    End If; 
End; 
/
CREATE SEQUENCE CDR.ExtDL_JobStatus_Seq 
    INCREMENT BY 1 
    START WITH 1 
    NOMAXVALUE 
    NOMINVALUE 
; 
/

SHOW ERRORS; 
Declare NumOfTriggers NUMBER :=0; 
Begin 
    SELECT COUNT(*) 
    INTO NumOfTriggers 
    FROM All_Triggers 
    WHERE 1=1 
    And upper (Owner) = upper ('CDR') 
    And upper (Trigger_Name) = upper ('ExtDL_JobStatus_SeqTrg'); 
    If NumOfTriggers > 0 Then 
    Execute IMMEDIATE 'DROP TRIGGER CDR.ExtDL_JobStatus_SeqTrg'; 
    End If; 
End; 
/
CREATE TRIGGER CDR.ExtDL_JobStatus_SeqTrg 
BEFORE INSERT 
ON CDR.ExtDL_JobStatus 
    FOR EACH ROW 
    WHEN (new.Id IS NULL) 
    BEGIN 
     SELECT ExtDL_JobStatus_Seq.nextval into :new.Id from dual; 
    END; 


/
SHOW ERRORS; 


insert into CDR.ExtDL_JobStatus (SHORTNAME, Description) VALUES (1, 1); 
insert into CDR.ExtDL_JobStatus (SHORTNAME, Description) VALUES (1, 1); 
insert into CDR.ExtDL_JobStatus (SHORTNAME, Description) VALUES (1, 1); 
select * FROM CDR.ExtDL_JobStatus 

當我與SHOW ERRORS運行(有多個地方存在),它只創建表,並完成。

DROP TABLE CDR.ExtDL_JobStatus succeeded. 
CREATE TABLE succeeded. 

當我刪除所有的顯示錯誤,下面是返回

DROP TABLE CDR.ExtDL_JobStatus succeeded. 
CREATE TABLE succeeded. 
anonymous block completed 
CREATE SEQUENCE succeeded. 
anonymous block completed 
TRIGGER CDR.ExtDL_JobStatus_SeqTrg Compiled. 
1 rows inserted 
1 rows inserted 
1 rows inserted 
ID      SHORTNAME    DESCRIPTION    
---------------------- ---------------------- ---------------------- 
1      1      1      
2      1      1      
3      1      1      

3 rows selected 

爲什麼執行在第一種情況下終止SHOW錯誤

+2

你用什麼工具? 'show errors'是一個SQL * Plus命令,看起來您正在使用其他工具來運行您的腳本。 – 2010-08-09 14:52:34

+0

我正在使用Oracle SQL Developer來運行我的腳本 – 2010-08-09 15:06:04

+0

如果您在命令之間僅放置了一行/,那麼行爲是否會更改?我會在每個SQL語句後面放一個。只是一個想法 - 祝你好運。 – 2010-08-09 16:34:50

回答

2

嘗試刪除';'在每個SHOW ERRORS之後。

SQL * Plus命令(如SET,SHOW ERRORS等)不需要;並且可能的是,可能會重新運行將導致「對象已存在」錯誤的緩衝區中的先前命令(即,CREATE SEQUENCE)。 (爲了證實這一點,我感到有點懶得觸發甲骨文)。

就個人而言,我總是指定完整的命令 - 即

SHOW ERRORS TRIGGER ExtDL_JobStatus_SeqTrg