例子如下

set serveroutput on;

declare
   V_SQL VARCHAR2(255);
   errorCode number; --异常编码  
   errorMsg varchar2(1000); --异常信息
   out_return varchar2(1000);
    flag varchar2(10);
CURSOR TP IS
  SELECT TABLE_NAME,CONSTRAINT_NAME FROM USER_CONSTRAINTS  WHERE CONSTRAINT_TYPE = 'P';
begin
    FOR E IN TP LOOP
    BEGIN
    V_SQL := 'ALTER TABLE ' || E.TABLE_NAME || ' ' || 'DISABLE' ||'  '|| 'CONSTRAINT ' || E.CONSTRAINT_NAME;
    DBMS_OUTPUT.PUT_LINE(V_SQL);
    EXECUTE IMMEDIATE (V_SQL);
     EXCEPTION
     when others then
         errorCode := SQLCODE;    
          errorMsg := SUBSTR(SQLERRM, 1, 200);   
              flag := 'false';  
        out_return := 'flag=' || flag || ',errorCode=' || errorCode || ',errorMsg=' || errorMsg;
        dbms_output.put_line(out_return);
      null;
    END;
   END LOOP;
end;

注意问题

1、捕捉异常后继续下一次循环需用

EXCEPTION
     when others then  null;

这样的结构。

2、在for ...LOOP   ENDLOOP 循环中捕捉异常,必须用begin   end 包起来,否则会报错。在PLSQL中报

PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following
    Error: PLS-00103: Encountered the symbol "END" when expecting one of the following

正确

FOR E IN TP LOOP
    begin
      ......................
     EXCEPTION
     when others then  null;

end;

endloop;

错误用法:

FOR E IN TP LOOP
      ......................
     EXCEPTION
     when others then  null;

endloop;

最新文章

  1. BT5 & Kali Linux 网卡选择
  2. mysql 查看存储引擎的状态 show engine innodb status 详解
  3. 转: Linux磁盘扩容
  4. SQLLite 学习笔记
  5. 怎么使用git来管理项目版本?
  6. HP QC IE11不支持( win7 64位 无法安装)解决方法
  7. [Js]评分星星
  8. Ruby on Rail 开发入门
  9. android传送照片到FTP服务器
  10. 只启动一个zookeeper配置 server1只需要配置一个
  11. Chapter 2 Open Book——11
  12. Discuz经典函数注释之authcode
  13. 0001.如何在Windows7(x64)上安装 Sharepoint2010 Fundation
  14. 34. leetcode 447. Number of Boomerangs
  15. php后台开源框架
  16. 51nod97B 异或约束和
  17. Timeline扩展功能实践指南
  18. python3.6小程序
  19. BMap:JavaScript API
  20. linux===sar命令性能监控

热门文章

  1. Couldn't import dot_parser, loading of dot files will not be possible. 解决方法
  2. Javascript中点击(click)事件的3种写法
  3. Mybatis的SqlSession理解(二)
  4. isnull和sum的关系
  5. [html]自定义滚动条风格
  6. vuex中的辅助函数 mapState,mapGetters, mapActions, mapMutations
  7. python三级菜单实例(傻瓜版和进阶版)
  8. PHP中如何命令行
  9. PHP里面增加写日志功能
  10. Entity Framework 6 学习笔记2 — 增、删、改、显示简单代码示例