触发器无效且重新验证失败
这是我用来创建表、序列和触发器的代码
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)
)
;
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
;
/
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 SEQUENCE 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_SeqTrg.nextval into :new.Id from dual;
END;
/
INSERT INTO ExtDL_JobStatus (Id, ShortName, Description) Values (0, 'Success', 'Fail')
/
SELECT * FROM ExtDL_JobStatus
当我执行代码时,我得到以下输出
DROP TABLE CDR.ExtDL_JobStatus succeeded.
CREATE TABLE succeeded.
anonymous block completed
CREATE SEQUENCE succeeded.
anonymous block completed
Warning: execution completed with warning
TRIGGER CDR.ExtDL_JobStatus_SeqTrg Compiled.
Error starting at line 62 in command:
INSERT INTO ExtDL_JobStatus (Id, ShortName, Description) Values (0, 'Success', 'Fail')
Error at Command Line:62 Column:12
Error report:
SQL Error: ORA-04098: trigger 'CDR.EXTDL_JOBSTATUS_SEQTRG' is invalid and failed re-validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause: A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed for the trigger.
*Action: Options are to resolve the compilation/authorization errors,
disable the trigger, or drop the trigger.
ID SHORTNAME DESCRIPTION
---------------------- ---------------------- ----------------------
0 rows selected
是什么使我的触发器无效?
Here is the code that I use to create a table, a sequence and a trigger
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)
)
;
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
;
/
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 SEQUENCE 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_SeqTrg.nextval into :new.Id from dual;
END;
/
INSERT INTO ExtDL_JobStatus (Id, ShortName, Description) Values (0, 'Success', 'Fail')
/
SELECT * FROM ExtDL_JobStatus
When I execute the code, I get the following output
DROP TABLE CDR.ExtDL_JobStatus succeeded.
CREATE TABLE succeeded.
anonymous block completed
CREATE SEQUENCE succeeded.
anonymous block completed
Warning: execution completed with warning
TRIGGER CDR.ExtDL_JobStatus_SeqTrg Compiled.
Error starting at line 62 in command:
INSERT INTO ExtDL_JobStatus (Id, ShortName, Description) Values (0, 'Success', 'Fail')
Error at Command Line:62 Column:12
Error report:
SQL Error: ORA-04098: trigger 'CDR.EXTDL_JOBSTATUS_SEQTRG' is invalid and failed re-validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause: A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed for the trigger.
*Action: Options are to resolve the compilation/authorization errors,
disable the trigger, or drop the trigger.
ID SHORTNAME DESCRIPTION
---------------------- ---------------------- ----------------------
0 rows selected
What makes my trigger invalid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是您的触发器编译失败的地方。
问题是因为您在代码中使用 ExtDL_JobStatus_SeqTrg,并且您创建的序列是 ExtDL_JobStatus_Seq。
另外,如果您尝试运行这样的脚本来创建(编译)对象,我建议您在每个触发器/过程/函数创建语句之后添加以下子句。
如果您的语句成功,则不会产生任何错误。如果出现任何错误,您将获得错误的详细描述,而不必再次执行脚本。
This is where your trigger compilation failed.
The problem is because you are using ExtDL_JobStatus_SeqTrg in your code and the sequence you created is ExtDL_JobStatus_Seq.
Also, if you are trying to run a script like this for creating (compiling) the objects, I would suggest you add the following clause after each trigger/procedure/function creatin statement.
If your statement succceds, that will just produce no errors. If there are any erros, you'll have a detailed description of the errors instead of having to execute the script again.
这是一个简单的拼写错误:您的序列名为
ExtDL_JobStatus_Seq
,但在触发器中引用ExtDL_JobStatus_SeqTrg.nextval
。为了将来参考,最好在每次编译 PL/SQL(触发器、过程等)的调用之后在脚本中包含一个显示错误的调用。像这样:
顺便说一句,在试图删除序列的匿名块中也存在相同的拼写错误。
It's a simple typo: your sequence is called
ExtDL_JobStatus_Seq
but in your trigger you referenceExtDL_JobStatus_SeqTrg.nextval
.For future reference it is a good idea to include a call to show error in scripts after each call which compiles PL/SQL (triggers, procedures, etc). Like this:
Incidentally, there's the same typo in the anonymous block which attempst to drop the sequence.
除了前面提到的所有内容之外,还有两个额外的拼写错误/错误:
DROP SEQUENCE
。In addition to everything previously mentioned, there are two additional typos/errors:
DROP SEQUENCE
.