触发要在更新属性上执行?
我的触发器有问题,但我找不到原因。
这些是表:
create table Properties(
idProperties number(10) NOT NULL ,
Type varchar2(45) NOT NULL,
ConstructionDate date NOT NULL,
FloorLocation varchar(20),
Balkony varchar2(10),
Price number(10) NOT NULL,
DateOfInsert date NOT NULL,
DateOfExiration date NOT NULL,
Address_FK number(20),
PropertyType_FK number(20) NOT NULL,
Service_FK number(20),
Ownership_FK number(20),
PropertyService_FK number(20))
create table Services(
idServices number(10) NOT NULL,
servicetype varchar2(20))
我正在尝试编写一个触发器,当状态字段从“新”更改为“已批准”时,在更新 PROPERTY
时执行,然后用今天的日期更新到期日期系统日期 + 90 天
。
我正在尝试此操作,但它不起作用:
CREATE OR REPLACE TRIGGER T22
AFTER UPDATE ON Properties
FOR EACH ROW
Begin
if :new.servicetype = 'APROVED' then
:new.Servicetype := SYSDATE + 90;
end if;
End;
我需要使用属性表中的外键调用 servicetype
吗?或者这是正确的,但我错过了一些东西?
I have a problem with triggers and I can't find why.
These are the tables:
create table Properties(
idProperties number(10) NOT NULL ,
Type varchar2(45) NOT NULL,
ConstructionDate date NOT NULL,
FloorLocation varchar(20),
Balkony varchar2(10),
Price number(10) NOT NULL,
DateOfInsert date NOT NULL,
DateOfExiration date NOT NULL,
Address_FK number(20),
PropertyType_FK number(20) NOT NULL,
Service_FK number(20),
Ownership_FK number(20),
PropertyService_FK number(20))
create table Services(
idServices number(10) NOT NULL,
servicetype varchar2(20))
I am trying write a trigger to be executed on update of a PROPERTY
when the status field is changed from “NEW” to “APPROVED” then update expiration date with today’s date Sysdate + 90 days
.
I am trying this but it doesn't work:
CREATE OR REPLACE TRIGGER T22
AFTER UPDATE ON Properties
FOR EACH ROW
Begin
if :new.servicetype = 'APROVED' then
:new.Servicetype := SYSDATE + 90;
end if;
End;
Do I need to call servicetype
with foreign key from the properties table? Or is this right but I am missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法更改
AFTER
触发器中的值。您需要使用BEFORE
触发器。如果您使用的是 Oracle 11.2,并且尝试定义更改值的
AFTER
触发器,则应该收到“ORA-04084:无法更改此触发器类型的新值”错误。 ,如果您将触发器创建为
BEFORE UPDATE
触发器,它应该可以工作You cannot change a value in an
AFTER
trigger. You would need to use aBEFORE
trigger.If you're using Oracle 11.2, you should get an "ORA-04084: cannot change NEW values for this trigger type" error if you try to define an
AFTER
trigger that changes a valueOn the other hand, if you create the trigger as a
BEFORE UPDATE
trigger, it should work您必须从服务类型表中进行选择才能查看实际的服务描述,以便您可以比较之前和之后的描述。
此外,当您更改要插入的值时,您必须将其更改为更新前触发器。
触发器定义:
测试:
You'll have to select from the service type table to see the actual service description so that you can compare the before and after descriptions.
Also, you'll have to change this to a before update trigger as you are changing the values that are about to be inserted.
Trigger definition :
Testing :