ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 今天修复数据写了个pl/sql

今天修复数据写了个pl/sql

原创 Linux操作系统 作者:paulyibinyi 时间:2008-08-06 11:34:54 0 删除 编辑

以下这个pl/sql 是针对业务数据出了问题

而进行修复的,涉及到一些判断

spool test.log
declare
   CURSOR emp_cur IS
  SELECT a.client_id client_id,
       b.login,
       b.login_uid,
       c.amount  amount,
       c.created_date created_date,
       c.status,
       d.after_balance  after_balance
  from tb_test_status a,
       tb_test b,
       (select account_id, amount,created_date,status
          from (select account_id,
                       amount,
                       created_date,
                       status,
                       row_number() over(partition by account_id order by created_date desc) rn
                  from tb_test_log
                 where account_id in (select client_id
                                        from tb_client_status
                                       where online_ = 'T'))
         where rn = 1) c,
       (select client_id, after_balance
          from (select client_id,
                       after_balance,
                       row_number() over(partition by client_id order by created_date desc) rn
                  from tb_test2_log
                 where client_id in (select client_id
                                       from tb_client_status
                                      where online_ = 'T')
                   and transaction_code_id = 3
                   and system_type = 2
                   and status = 1)
         where rn = 1) d

 where a.online_ = 'T'
   and a.client_id = b.id
   and c.account_id = b.id
   and a.client_id = d.client_id(+);

      ---以上是定义个游标
   emp_rec emp_cur%ROWTYPE;
   cashtransfer_date date;
   cashflow_date date;
 
BEGIN
   FOR emp_rec IN emp_cur LOOP     --for循环
     select nvl(max(created_date),to_date('1970-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) into cashtransfer_date
      from tb_cashtransfer_log where account_id=emp_rec.client_id;
     select nvl(max(created_date),to_date('1970-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) into cashflow_date
   from tb_cashflow_log where client_id=emp_rec.client_id and transaction_code_id=3 and system_type=2 and status=1;
    if cashtransfer_date>cashflow_date then     --判断
       update tb_test_log set tb_cashtransfer_log.status=0 where account_id=emp_rec.client_id and created_date=emp_rec.created_date;
       update tb_test set credit_amount=emp_rec.AMOUNT,LAST_MODIFIED_DATE=sysdate Where id=emp_rec.client_id;
       update tb_test_status set LOCATION_TYPE=0,ONLINE_='F',LAST_MODIFIED_DATE=sysdate Where client_id=emp_rec.client_id;
      
    
    else
      update tb_test_log set status=2 where account_id=emp_rec.client_id and created_date=emp_rec.created_date;
      insert into tb_test_log
      (transfer_type,account_type,account_id,amount,login_uid,status,created_date,last_modified_date,ref_no)
      values
      (2,1,emp_rec.client_id,emp_rec.after_balance,emp_rec.login_uid,2,sysdate,sysdate,' ');
      update tb_test_status set LOCATION_TYPE=0,ONLINE_='F',LAST_MODIFIED_DATE=sysdate,Cashtransferid=S_TB_CASHTRANSFER_LOG.currval Where client_id=emp_rec.client_id;
      update tb_test set credit_amount=emp_rec.after_balance,LAST_MODIFIED_DATE=sysdate Where id=emp_rec.client_id;
    
   
    end if;
  end loop;
  commit;

END;
/
spool off;
exit;


 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7199859/viewspace-420479/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
学习数据库

注册时间:2007-12-11

  • 博文量
    907
  • 访问量
    6894208