我在Oracle中有一个调用sys.dbms_alert.signal
的触发器。 DevArt OracleAlerter
在自托管服务中接收这些警报。
但是,我发现即使对于多次删除/更新/插入,OracleAlerter
只会收到一个记录的提醒,而不是所有<的一个提醒/ strong>的记录。
有没有办法查看在Oracle(11g)中触发的信号的历史记录或日志?
这是发送警报的触发器类型的示例:
create or replace trigger MACL.ZM_SOCOMM_trigger
after delete or insert or update on MACL.SOCOMM
for each row
declare
alertData varchar2(1000);
begin
alertData := '{"Schema":"MACL","Table":"SOCOMM","Index":"I_SOCOM_KEY","Columns":[{"COLUMN_NAME":"SOCOM_ORDREF","COLUMN_POSITION":1,"COLUMN_VALUE":"#SOCOM_ORDREF#"},{"COLUMN_NAME":"SOCOM_ORDLINE","COLUMN_POSITION":2,"COLUMN_VALUE":"#SOCOM_ORDLINE#"},{"COLUMN_NAME":"SOCOM_COMSEQ","COLUMN_POSITION":3,"COLUMN_VALUE":"#SOCOM_COMSEQ#"},{"COLUMN_NAME":"SOCOM_COMTYPE","COLUMN_POSITION":4,"COLUMN_VALUE":"#SOCOM_COMTYPE#"},{"COLUMN_NAME":"SOCOM_TEXT","COLUMN_POSITION":5,"COLUMN_VALUE":"#SOCOM_TEXT#"}],"ChangePlaceHolder":"#CHANGE#"}';
IF INSERTING OR UPDATING THEN
alertData := replace(alertData, '#SOCOM_ORDREF#', :new.SOCOM_ORDREF);
alertData := replace(alertData, '#SOCOM_ORDLINE#', :new.SOCOM_ORDLINE);
alertData := replace(alertData, '#SOCOM_COMSEQ#', :new.SOCOM_COMSEQ);
alertData := replace(alertData, '#SOCOM_COMTYPE#', :new.SOCOM_COMTYPE);
alertData := replace(alertData, '#SOCOM_TEXT#', :new.SOCOM_TEXT);
ELSIF DELETING THEN
alertData := replace(alertData, '#SOCOM_ORDREF#', :old.SOCOM_ORDREF);
alertData := replace(alertData, '#SOCOM_ORDLINE#', :old.SOCOM_ORDLINE);
alertData := replace(alertData, '#SOCOM_COMSEQ#', :old.SOCOM_COMSEQ);
alertData := replace(alertData, '#SOCOM_COMTYPE#', :old.SOCOM_COMTYPE);
alertData := replace(alertData, '#SOCOM_TEXT#', :old.SOCOM_TEXT);
END IF;
IF INSERTING THEN
alertData := replace(alertData, '#CHANGE#', 'INSERT');
ELSIF DELETING THEN
alertData := replace(alertData, '#CHANGE#', 'DELETE');
ELSE
alertData := replace(alertData, '#CHANGE#', 'UPDATE');
END IF;
sys.dbms_alert.signal('ooalert_sync', alertData);
END;
以下是我用来订阅Oracle发出的信号的代码:
public void SetUpAlerts() => RegisterHandlers(CreateAlerter());
private static void RegisterHandlers(OracleAlerter alerter)
{
alerter.Alert += AlerterOnAlert;
alerter.Error += AlerterOnError;
alerter.WaitTimeout += AlerterOnWaitTimeout;
alerter.Stopped += AlerterOnStopped;
alerts.Add(alerter);
alerter.Start();
}
private OracleAlerter CreateAlerter() => new OracleAlerter
{
Timeout = Day,
AlertName = "Name",
Connection = Factory.CreateSourceConnection() as OracleConnection
};
private static void AlerterOnAlert(object sender, OracleAlerterAlertEventArgs args)
{
//handle alert
}
修改
我在触发器中添加了一个语句,每次触发器触发时都会将一些数据插入到审计表中,并且看起来触发器的触发次数是正确的。
答案 0 :(得分:1)
根据文件:
警报可以比相应的应用程序等待调用更频繁地发出信号。在这种情况下,旧的警报将被丢弃。应用程序始终获取最新警报(基于事务提交时间)。
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_alert.htm#ARPLS65178