使用存储过程监视 table 属性

Monitoring a table attribute with stored procdeure

我正在开发一个存储过程,用于监视 table 中的 Last_Extract_Ts 值,该值提供有关 Extract Transform Load(ETL) 的信息。现在我想检查 Last_Extract_ts 值是否与上次过程 运行 相比发生了变化,但我不太清楚如何存储上次过程 运行 的结果,以便我可以用在现在的。

下面是我的程序

create or replace PROCEDURE MONITOR AS


  v_count               number:=0;
  v_Last_Extract_Ts VARCHAR2(80) := '';
  v_Last_ETL_Run VARCHAR2(80) := '';
  BEGIN

select count(*) into v_count from oms_etl_config where ATTR_NM='last_extract_ts' and process_type='upd' and ATTR_VALUE<=to_char(sys_extract_utc(systimestamp)-5/1440,'YYYY-MM-DD HH24:MI:SS');
select Attr_value into v_Last_Extract_Ts from OMS_ETL_CONFIG where PROCESS_TYPE='upd' AND ATTR_NM='last_extract_ts';
Select MAX(START_TS) into v_Last_ETL_Run from  OMS_ETL_AUDIT;

dbms_output.put_line(v_count);
dbms_output.put_line(v_Last_Extract_Ts);
dbms_output.put_line(v_Last_ETL_Run);


END;

我在 Insert results of a stored procedure into a temporary table , Exec stored procedure into dynamic temp table 中遇到了类似将存储过程的结果存储在临时 table 中的东西,但我不太明白它如何满足我的需要。

我正在努力实现的目标是可能的还是我需要采用不同的方法。

提前致谢。

P.S. I am absolute beginner with PL/SQL and stored procedures so I am not having any attempt in my post to show for the research I have done. Sorry for that.

最简单的方法是将最后的结果保存在 table 中。

创建 table:

Create table monitor_results 
( 
  last_run_date          date
, last_Last_Extract_Ts  varchar2(80)
, last_ETL_Run          varchar2(80)
, last_count            NUMBER
);

初始化值:

insert into monitor_results values (NULL, NULL, NULL, NULL);
commit;

在存储过程中更新 table 中的值:

...

update monitor_results
set 
      last_run_date         = SYSDATE
    , last_Last_Extract_Ts  = v_Last_Extract_Ts
    , last_ETL_Run          = v_Last_ETL_Run
    , last_count            = v_count
;
commit;

您可以使用触发器进行此检查:见下文:

CREATE OR REPLACE TRIGGER reporting_trigger
   AFTER UPDATE ON <Table>
   FOR EACH ROW
BEGIN
 /**Your column which holds the record**/
IF :new.a = :old.a THEN 
   raise_application_error( -20001, 'This is a custom error' );

 END IF;


END;