问题描述:目前有两台oracle数据库服务器的数据需要交互,使用的是datalink的形式进行,但是由于其中一台数据库服务器(其他厂家的)经常因为网络问题,导致连接不上或者连接超时,导致调用存储过程进行相关数据交互操作的时候,出现异常了。      目前,希望通过ORACLE的异常处理,来捕获这个异常,当出现这个异常的时候,将数据进行回滚操作,来保证数据的一致性,但是,不知道该捕获哪种异常,该怎么操作,求大神指点!(打算在进行数据操作前,先使用连接串查询下数据,判断能否正常连接,如果没有异常则直接对数据进行操作,但是不知道怎么写)
declare 
  v_ErrorCode NUMBER;           -- Variable to hold the error message code  
  v_ErrorText VARCHAR2(200);    -- Variable to hold the error message text  
  i number;
begin
  -- Test statements here
  select count(*) into i  from  psbob_realtime.ln@fzems ;
  Exception 
    when Timeout_on_resource then 
      --do something 
    when others then 
      v_ErrorCode := SQLCODE;  
      v_ErrorText := SUBSTR(SQLERRM, 1, 200);
      
  dbms_output.put_line(v_ErrorCode || '::'||v_ErrorText);     
end;用上面的来捕获异常捕获不了 ,求大神指点 ,感激不尽!

解决方案 »

  1.   


    declare 
      v_errorcode number;           -- variable to hold the error message code  
      v_errortext varchar2(200);    -- variable to hold the error message text  
      i number;
    begin  select count(*) into i from psbob_realtime.ln@fzems;
       
      dbms_output.put_line('总数为:'||i); 
    exception 
        when others then 
          v_errorcode := sqlcode;  
          v_errortext := substr(sqlerrm, 1, 200);
          dbms_output.put_line(v_errorcode || '::'||v_errortext);     
    end;
      

  2.   

    之前回复过类似的一个问题DECLARE
     num number;
     BEGIN
         BEGIN
           EXECUTE IMMEDIATE 'select count(*) from dual@os_ns';
                   dbms_output.put_line('ok');    
           EXCEPTION
               WHEN OTHERS THEN
                 dbms_output.put_line('timeout');       
                  raise;
          END;
          
          DBMS_OUTPUT.put_line('continue....');
     END;