PL/SQL 为什么我在触发操作时出现 DEADLOCK?
PL/SQL Why I get DEADLOCK on trigger action?
我有以下触发器
CREATE OR REPLACE TRIGGER LAST_EDIT
BEFORE UPDATE ON MESSAGES
FOR EACH ROW
DECLARE
pragma autonomous_transaction;
BEGIN
if :NEW.TEXT <> :OLD.TEXT THEN
UPDATE MESSAGES set MESSAGES.LAST_EDITED=(select USERS.EMAIL from USERS inner join LAST_EDITED_TABLE on users.ID=LAST_EDITED_TABLE.USER_ID where
LAST_EDITED_TABLE.MESSAGE_ID=(select MESSAGE_ID from LAST_EDITED_TABLE where DATE_MESSAGE=(select max(DATE_MESSAGE) from LAST_EDITED_TABLE )));
ENDIF;
COMMIT;
END;
然后出现以下错误
ORA-06512: at "DIP.MESSAGEPACKAGE", line 35
00060. 00000 - "deadlock detected while waiting for resource"
*Cause: Transactions deadlocked one another while waiting for resources.
*Action: Look at the trace file to see the transactions and resources
involved. Retry if necessary
我正在尝试更新表明谁进行了最后一次更新的行(同一 table 中的一行)。谁能帮帮我?
这不是你真正需要的吗?
CREATE OR REPLACE TRIGGER LAST_EDIT
BEFORE UPDATE ON MESSAGES
FOR EACH ROW
DECLARE
email USERS.EMAIL%type;
BEGIN
if :NEW.TEXT <> :OLD.TEXT THEN
select USERS.EMAIL into email
from USERS inner join LAST_EDITED_TABLE on users.ID=LAST_EDITED_TABLE.USER_ID
where LAST_EDITED_TABLE.MESSAGE_ID = (select MESSAGE_ID from LAST_EDITED_TABLE where DATE_MESSAGE = (select max(DATE_MESSAGE) from LAST_EDITED_TABLE ));
:NEW.LAST_EDITED = email;
END IF;
COMMIT;
END;
/
查找电子邮件的查询逻辑也太复杂了。当然你可以简化它。
我有以下触发器
CREATE OR REPLACE TRIGGER LAST_EDIT
BEFORE UPDATE ON MESSAGES
FOR EACH ROW
DECLARE
pragma autonomous_transaction;
BEGIN
if :NEW.TEXT <> :OLD.TEXT THEN
UPDATE MESSAGES set MESSAGES.LAST_EDITED=(select USERS.EMAIL from USERS inner join LAST_EDITED_TABLE on users.ID=LAST_EDITED_TABLE.USER_ID where
LAST_EDITED_TABLE.MESSAGE_ID=(select MESSAGE_ID from LAST_EDITED_TABLE where DATE_MESSAGE=(select max(DATE_MESSAGE) from LAST_EDITED_TABLE )));
ENDIF;
COMMIT;
END;
然后出现以下错误
ORA-06512: at "DIP.MESSAGEPACKAGE", line 35
00060. 00000 - "deadlock detected while waiting for resource"
*Cause: Transactions deadlocked one another while waiting for resources.
*Action: Look at the trace file to see the transactions and resources
involved. Retry if necessary
我正在尝试更新表明谁进行了最后一次更新的行(同一 table 中的一行)。谁能帮帮我?
这不是你真正需要的吗?
CREATE OR REPLACE TRIGGER LAST_EDIT
BEFORE UPDATE ON MESSAGES
FOR EACH ROW
DECLARE
email USERS.EMAIL%type;
BEGIN
if :NEW.TEXT <> :OLD.TEXT THEN
select USERS.EMAIL into email
from USERS inner join LAST_EDITED_TABLE on users.ID=LAST_EDITED_TABLE.USER_ID
where LAST_EDITED_TABLE.MESSAGE_ID = (select MESSAGE_ID from LAST_EDITED_TABLE where DATE_MESSAGE = (select max(DATE_MESSAGE) from LAST_EDITED_TABLE ));
:NEW.LAST_EDITED = email;
END IF;
COMMIT;
END;
/
查找电子邮件的查询逻辑也太复杂了。当然你可以简化它。