存储过程学习

create or replace procedure CheckCorpName AS
  v_count     integer;
  v_corp_org  integer;
  v_corp_id   integer;
  v_old_name  varchar2(200);
  v_new_name  varchar2(200);
  V_ERRORCODE NUMBER;
  V_ERRORTEXT VARCHAR2(300);

  CURSOR c_1 IS
    select a.org, a.id, a.corp_name new_name, b.corp_name old_name
      from t_corp@gsnwdblink a, t_ccp_label_corp2 b
     where a.org = b.corp_org
       and a.id = b.corp_id
       and a.corp_name <> b.corp_name
       and (a.come_out is null or a.come_out = '0')
       And a.cancel_flag Is Null
       and a.corp_status is not null;
  v_cursor1 c_1%rowtype;
BEGIN
  open c_1; --open;
  loop
    fetch c_1
      into v_cursor1;
    exit when c_1%NOTFOUND;
    v_corp_org := v_cursor1.org;
    v_corp_id  := v_cursor1.id;
    v_old_name := v_cursor1.old_name;
    v_new_name := v_cursor1.new_name;
    select count(*)
      into v_count
      from T_CCP_OLD_NAME_NAME
     where corp_org = v_corp_org
       and corp_id = v_corp_id;
    if v_count = 0 then
      insert into T_CCP_OLD_NAME_NAME
      values
        (v_old_name, v_new_name, v_corp_org, v_corp_id, sysdate);
    end if;
  end loop;

  commit;
  close c_1;
EXCEPTION
  when others THEN
    ROLLBACK;
    --close c_cursor2;
    V_ERRORCODE := SQLCODE;
    V_ERRORTEXT := SUBSTR(SQLERRM, 1, 250);
    COMMIT;
END;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值