如果不可以的话,请问在Oracel数据库中如何保护异常,比如在Drop index时报告无此索引时,我执行下一步操作?谢谢啦!紧急求救!

解决方案 »

  1.   

    不可以replace
    可将出现异常的部分放进一个单独的块中(begin...end)或放进另一个存储过程
    begin
    ...
       begin
       ...
       exception
       ...
       end;
    ...
    exception
    end;
    /
      

  2.   

    谢谢!但是我这么做了仍然报错,下面是存储过程:
    Create or replace procedure Proc_HourData (StartDate In VARCHAR2)Begin---大循环
    --其他语句开始
    ...--其他语句结束
    --下面是捕获的begin end块    --创建索引
        begin
        mSQLStr := 'drop index mIdx_Res_Working';
        execute immediate mSQLStr;
        exception
        end;  
        
        begin    
        mSQLStr := 'drop index mIdx_SrvUnit';
        execute immediate mSQLStr;
        exception
        end;
        
        begin    
        mSQLStr := 'drop index mIdx_SrvUnit1';
        execute immediate mSQLStr;
        exception
        end;
            
        commit;
        mSQLStr := 'create index mIdx_Res_Working on
            Tbl_Res_WorkingTmp
            (StartTime , ContactID ,ReSourceID ,ReSourceType)';
        execute immediate mSQLStr;    mSQLStr := 'create index mIdx_SrvUnit on
            Tbl_SrvUnitTmp
            (a)';
        execute immediate mSQLStr;
        commit;
    ---下面是其他语句
    End;不知道为何老是报告错误,错误描述是:“出现符号End”在需要下列之一时,pragma when;小弟对oracle这种编程不是很熟悉,能否给出一个详细的例子来。谢谢了。我一定会给分的。不胜感激。
    End前面一定要加when吗?
      

  3.   

    create or replace procedure testpro
    as
    begin begin
     execute immediate 'drop index test;';
     exception 
      when others then
      null;
     end;
     dbms_output.put_line('成功执行');
    end;
    /
      

  4.   

    另外,需要说明的是如果发生异常,捕获异常后能否顺利执行下面的脚本。比如:    begin    
        mSQLStr := 'drop index mIdx_SrvUnit1';
        execute immediate mSQLStr;
        exception
        when others then
        null;
        end;
       ---以上捕获了错误,下面的语句能执行吗?
            
        commit;
        mSQLStr := 'create index mIdx_Res_Working on
            Tbl_Res_WorkingTmp
            (StartTime , ContactID ,ReSourceID ,ReSourceType)';
        execute immediate mSQLStr;    mSQLStr := 'create index mIdx_SrvUnit on
            Tbl_SrvUnitTmp
            (a)';
        execute immediate mSQLStr;
        commit;