当Items.Status从任何小于20的值更新为20时,需要创建触发器,而不是大于20的值。
触发器应该使用Status.Status_Desc =" Packed"
更新相应Item_Id的状态表。到目前为止,我已经能够创建一个类似于下面的触发器,它可以很好地编译,但不会给我预期的结果。请帮忙
create or replace trigger test_trg
after update on items
referencing old as old new as new
for each row
--select item_id into
begin
if (:old.status < 20 and :new.status=20) then
update status
set status_desc='packed'
where Item_Id =1 /*Justfor testing purpose, this need to be matched with item_id in ITEMS table */
end if;
end;
创建表格的脚本
CREATE TABLE "ITEMS" ("ITEM_ID" NUMBER, "ITEM_NAME" VARCHAR2(100), "STATUS" NUMBER)
REM INSERTING into ITEMS
SET DEFINE OFF;
Insert into ITEMS (ITEM_ID,ITEM_NAME,STATUS) values (1,'Test',10);
Insert into ITEMS (ITEM_ID,ITEM_NAME,STATUS) values (2,'Test1',30);
CREATE TABLE "STATUS" ("ITEM_ID" NUMBER, "STATUS_DESC" VARCHAR2(100))
REM INSERTING into STATUS
SET DEFINE OFF;
Insert into STATUS (ITEM_ID,STATUS_DESC) values (1,'testing');
Insert into STATUS (ITEM_ID,STATUS_DESC) values (2,'testing');