0

我创建了一个 oracle 存储过程来根据事务 rowid 和时间戳从 logminer 获取数据。该过程应尝试从 logminer 中进行选择,如果在此会话上启动 logminer 时失败,则应启动它并选择数据。问题是每次程序在同一个会话上启动 logminer

    create or replace PROCEDURE TRACK_TRACK (
CDC_TIMESTAMP IN VARCHAR2
,CDC_ROW_ID IN VARCHAR2
,SESSION_NUMBER OUT VARCHAR2
,SERIAL_NUMBER OUT VARCHAR2
,OS_USERNAME OUT VARCHAR2
,MACHINE_NAME OUT VARCHAR2
)
AS
V_LOG_NAME VARCHAR2 (256);
V_CDC_TIME DATE;
V_ROW_ID VARCHAR2 (18);
V_CDC_TIMESTAMP timestamp := to_timestamp (CDC_TIMESTAMP,'YYYYMMDDHH24MISSFF9');

BEGIN
SELECT session#,SERIAL#,'2',MACHINE_NAME,ROW_ID INTO SESSION_NUMBER,SERIAL_NUMBER,OS_USERNAME,MACHINE_NAME,V_ROW_ID FROM V$LOGMNR_CONTENTS 
Where ROW_ID=CDC_ROW_ID and TIMESTAMP=V_CDC_TIMESTAMP;
  EXCEPTION
  WHEN others
  THEN
        BEGIN
DBMS_LOGMNR.START_LOGMNR (STARTTIME=> SYSDATE-1,ENDTIME=>SYSDATE, OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG 
                                                                                            + DBMS_LOGMNR.CONTINUOUS_MINE);
                                             
                                              
SELECT session#,SERIAL#,'1',MACHINE_NAME,ROW_ID INTO SESSION_NUMBER,SERIAL_NUMBER,OS_USERNAME,MACHINE_NAME,V_ROW_ID FROM V$LOGMNR_CONTENTS 
Where ROW_ID=CDC_ROW_ID and TIMESTAMP=V_CDC_TIMESTAMP;END;
  
    
END TRACK_TRACK;

如何控制它以使 logminer 不会每次都启动?

4

1 回答 1

0

其他人除外

请尝试用异常 ORA-1306 替换它并测试几次,因为它可能会在内部引发其他错误:

CREATE OR REPLACE PROCEDURE TRACK_TRACK (
    CDC_TIMESTAMP IN VARCHAR2
   ,CDC_ROW_ID IN VARCHAR2
   ,SESSION_NUMBER OUT VARCHAR2
   ,SERIAL_NUMBER OUT VARCHAR2
   ,OS_USERNAME OUT VARCHAR2
   ,MACHINE_NAME OUT VARCHAR2
)
AS
--   V_LOG_NAME VARCHAR2 (256);
--   V_CDC_TIME DATE;
   V_ROW_ID VARCHAR2 (18);
   V_CDC_TIMESTAMP timestamp := to_timestamp (CDC_TIMESTAMP,'YYYYMMDDHH24MISSFF9');

   E_LOGNR_START exception;
   pragma exception_init(E_LOGNR_START, -1306);

   cursor cr is
      SELECT session#,SERIAL#,'2',MACHINE_NAME,ROW_ID
      FROM V$LOGMNR_CONTENTS
      Where ROW_ID=CDC_ROW_ID
        and TIMESTAMP=V_CDC_TIMESTAMP;

   procedure p is
   begin
      open cr;
      fetch cr INTO SESSION_NUMBER,SERIAL_NUMBER,OS_USERNAME,MACHINE_NAME,V_ROW_ID;
      close cr;
   exception when others then
      close cr;
      raise;
   end p;
BEGIN
   p();
EXCEPTION
   WHEN E_LOGNR_START THEN
       BEGIN
           DBMS_LOGMNR.START_LOGMNR (
              STARTTIME => SYSDATE-1,
              ENDTIME   => SYSDATE,
              OPTIONS   => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + DBMS_LOGMNR.CONTINUOUS_MINE
           );
           p();
       END;
END TRACK_TRACK;
/
于 2020-07-07T15:29:20.440 回答