• oracle 游标循环, 查询,异常捕获,继续执行


    declare
           --类型定义
           strsql string(500);
            v_ErrorCode NUMBER;           -- Variable to hold the error message code  
            v_ErrorText VARCHAR2(200);    -- Variable to hold the error message text  
           cursor c_eventstate
           is
           Select  CampaignId,phonenumber,PolicyNumber from mkt_eventstate a where synstate =0 and packagestate = 2 and errorcode = 6;
           --定义一个游标变量v_cinfo c_emp%ROWTYPE ,该类型为游标c_emp中的一行数据类型
           c_row c_eventstate%rowtype;
    begin
           for c_row in c_eventstate loop
              begin
              strsql:='select * from mkt_userprizeinfo t where t.campaignid='||c_row.CampaignId||' and t.userid='||c_row.phonenumber||' and t.PolicyNumber='''||c_row.PolicyNumber||'''';
              execute immediate strsql ;
             dbms_output.put_line(c_row.CampaignId||'-'||c_row.phonenumber||'-'||c_row.PolicyNumber);
            -- RAISE_APPLICATION_ERROR(-20001,'数值不能为0');
              EXCEPTION
             --捕捉异常
             WHEN others THEN
               begin
                  v_ErrorCode := SQLCODE;  
                  v_ErrorText := SUBSTR(SQLERRM, 1, 200); 
               DBMS_OUTPUT.put_line('捕获了错误begin');
               dbms_output.put_line(c_row.CampaignId||'-'||c_row.phonenumber||'-'||c_row.PolicyNumber||'-'||v_ErrorCode || '::'||v_ErrorText);
               DBMS_OUTPUT.put_line('捕获了错误end');
               end;
             end;
           
           end loop;    
    end;

  • 相关阅读:
    LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
    [转载]弹出一个不带地址栏、工具栏的IE非模态窗口
    winform datagridview 如何设置datagridview隔行变色
    C#调用C++的dll存在的问题
    Seafile开源私有云自定义首页Logo图片
    Alpine Linux 安装 lxml Pillow 失败
    Docker容器 MySQL中文乱码解决方案
    JS 查找数组的父节点及祖先节点
    五分钟读懂UML类图(转)
    Ant Design按需加载
  • 原文地址:https://www.cnblogs.com/linbl/p/4565746.html
Copyright © 2020-2023  润新知