Oracle dbms_alert.signal 为多个操作触发一次
Oracle dbms_alert.signal firing once for multiple actions
我在 Oracle 中有一个调用 sys.dbms_alert.signal
的触发器。 DevArt OracleAlerter
在自托管服务中接收这些警报。
但是,我发现即使对于多个 deletes/updates/inserts,OracleAlerter
也只会收到 一个 记录的警报,而不是一个警报全部条记录。
有没有办法查看在 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
}
编辑
我在触发器中添加了一条语句,每次触发器触发时都会将一些数据插入到审计中 table,触发器似乎被触发了正确的次数。
根据文档:
Alerts can be signalled more often than the corresponding application wait calls. In such cases, the older alerts are discarded. The application always gets the latest alert (based on transaction commit times).
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_alert.htm#ARPLS65178
我在 Oracle 中有一个调用 sys.dbms_alert.signal
的触发器。 DevArt OracleAlerter
在自托管服务中接收这些警报。
但是,我发现即使对于多个 deletes/updates/inserts,OracleAlerter
也只会收到 一个 记录的警报,而不是一个警报全部条记录。
有没有办法查看在 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
}
编辑
我在触发器中添加了一条语句,每次触发器触发时都会将一些数据插入到审计中 table,触发器似乎被触发了正确的次数。
根据文档:
Alerts can be signalled more often than the corresponding application wait calls. In such cases, the older alerts are discarded. The application always gets the latest alert (based on transaction commit times).
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_alert.htm#ARPLS65178