ORACLE 简单存储过程

实现每日同步一个表的昨日的数据至另一个表

用merge 实现

控制台打印输出     set serveroutput on 

CREATE OR REPLACE PROCEDURE ML_SYNC_LOG_JOB_FROM_SAP
AS
  /*****************************************************************************
  PROCEDURE NAME     : ML_SYNC_LOG_JOB_FROM_SAP
  DESCRIPTION        : This stored procedure sync log of SAP sync to-do time from SAP
  CREATE BY          : 
  LAST MODIFIED BY   : 
  *****************************************************************************/
BEGIN
  BEGIN
    MERGE INTO ml_sys_log_job_for_sap dst USING
    (SELECT FD_START_TIME,
      FD_END_TIME,
      FD_TASK_DURATION,
      FD_SUBJECT,
      FD_SUCCESS
    FROM sys_log_job
    WHERE FD_SUBJECT         = '同步SAP系统待办列表'
    AND TRUNC(FD_START_TIME) = TRUNC(SYSDATE) - 1
    ORDER BY FD_START_TIME
    ) src ON (dst.START_TIME = src.FD_START_TIME)
  WHEN MATCHED THEN
    UPDATE
    SET dst.END_TIME    = src.FD_END_TIME,
      dst.TASK_DURATION = src.FD_TASK_DURATION,
      dst.SUBJECT       = src.FD_SUBJECT,
      dst.SUCCESS_FLAG  = src.FD_SUCCESS 
  WHEN NOT MATCHED THEN
    INSERT
      (
        START_TIME,
        END_TIME,
        TASK_DURATION,
        SUBJECT,
        SUCCESS_FLAG
      )
      VALUES
      (
        src.FD_START_TIME,
        src.FD_END_TIME,
        src.FD_TASK_DURATION,
        src.FD_SUBJECT,
        src.FD_SUCCESS
      );
    COMMIT;
  EXCEPTION
  WHEN OTHERS THEN
    ROLLBACK;
    DBMS_OUTPUT.PUT_LINE('Completed with error : '||sqlerrm);
  END ;
  COMMIT;
  DBMS_OUTPUT.PUT_LINE('Finished!');
END ML_SYNC_LOG_JOB_FROM_SAP;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值