簡體   English   中英

使用編譯錯誤更新觸發器成功

[英]update trigger success with compilation error

我正在嘗試使用oracle中的觸發器,根據表1中的字段中更新的值來更新表2中的字段

create or replace trigger update_value
AFTER  update of field_1 on table_1
for each row 
begin
if(:New.field_1 = 'y') then 
update table_2
set field_2 = 'updated'
from table_1
where table_1.id = table_2.id

end if;
end;

如果觸發器或任何其他存儲的PL / SQL代碼編譯時出現錯誤或警告,則可以通過show errors來查看實際的問題(如果您的客戶端支持; SQL * Plus和SQL Developer可以執行); 或者,您可以在user_errorsall_errors視圖中查詢適當的對象類型和名稱,例如:

select * from user_errors where type = 'TRIGGER' and name = 'UPDATE_VALUE';

您擁有的代碼將得到PLS-00103: Encountered the symbol ";" ... PLS-00103: Encountered the symbol ";" ... 您在update語句后沒有分號。 如果添加,則會得到PL/SQL: ORA-00933: SQL command not properly ended因為更新語句中不能包含from子句(除非有子查詢)。

您無需直接引用table_1 您已經在使用一個:NEW變量,您只需要使用另一個:

create or replace trigger update_value
after update of field_1 on table_1
for each row 
begin
  if :NEW.field_1 = 'y' then 
    update table_2
    set field_2 = 'updated'
    where id = :NEW.id;
  end if;
end;
/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM