我的问题是下面详述的触发器似乎正确执行,除了更新语句 UPDATE my_dblist
SET passive_servername = v_newpassive WHERE server = :NEW.server AND dbname = :NEW.dbname;
似乎没有发生。旧记录被删除并正确插入到历史记录中,但新记录没有在passive_servername 下列出旧的活动服务器。我有一种感觉,这可能与它的自主性有关?
create or replace
TRIGGER cluster_check
AFTER INSERT ON my_dblist
FOR EACH ROW
DECLARE
pragma autonomous_transaction;
v_duplicates NUMBER;
v_newpassive varchar2(30);
BEGIN
SELECT count(*) INTO v_duplicates FROM my_dblist WHERE passive_servername = :new.server and dbname = :new.dbname order by 1;
IF v_duplicates > 0
THEN
SELECT server INTO v_newpassive FROM my_dblist WHERE passive_servername = :NEW.server AND dbname = :NEW.dbname ORDER BY 1;
UPDATE my_dblist
SET passive_servername = v_newpassive WHERE server = :NEW.server AND dbname = :NEW.dbname;
INSERT INTO my_dblist_history
SELECT * FROM my_dblist WHERE passive_Servername = :NEW.server AND dbname = :NEW.dbname;
DELETE FROM my_dblist
WHERE passive_Servername = :NEW.server AND dbname = :NEW.dbname;
END IF;
commit;
END;