exception
   when NO_DATA_FOUND THEN NULL;

解决方案 »

  1.   

    一楼的insert into tableOld(tid2,tname2)values(v_tid,v_tname);
    不执行了
      

  2.   

    因为找不到记录后,会直接跳转到exception的,而不会去执行insert语句的,而且你就是把insert语句放到exception中后,那么一个存储过程中有很多类似的过程,那不是很麻烦,特别是对潜套的,而且这样不利于存储过程的维护!
      

  3.   

    直接用merge into不可以么?
      

  4.   

    1. 使用merge处理..2. 先update 如果sql%rowcount = 0就insert.
      

  5.   

    DECLARE
          V_BOOLEAN BOOLEAN:=TRUE;
       BEGIN 
          BEGIN
             select tid ,tname into v_tid,v_tname from table where fid=v_fid;
          EXCEPTION
             WHEN NO_DATA_FOUND THEN
                  V_BOOLEAN:=FALSE;
          END;
       if V_BOOLEAN:=TRUE then
          update tableOld set tname2=v_tname where tid2=v_tid;
       else
          insert into tableOld(tid2,tname2)values(v_tid,v_tname);
       end if;
       commit;
       END;
      

  6.   

    晕,可以很简单的阿,楼主的思路是很常用的方法
    v_count number:=0;
    begin
    select count('x') into v_count from table where fid=v_fid;
    if v_count = 0 then
      insert into tableOld(tid2,tname2)values(v_tid,v_tname);
      -- v_tid,v_tname 的值要考虑考虑哦
    else
      select tid ,tname into v_tid,v_tname from table where fid=v_fid;
      update tableOld set tname2=v_tname where tid2=v_tid;
    end if;
    commit;
      

  7.   

    楼上的方法不行,如果符合条件的记录不存在,根本就不能into,会发生异常,那样v_count哪有什么值
    DECLARE
          V_BOOLEAN BOOLEAN:=TRUE;
       BEGIN 
          BEGIN
             select tid ,tname into v_tid,v_tname from table where fid=v_fid;
          EXCEPTION
             WHEN NO_DATA_FOUND THEN
                  V_BOOLEAN:=FALSE;
          END;
       if V_BOOLEAN:=TRUE then
          update tableOld set tname2=v_tname where tid2=v_tid;
       else
          insert into tableOld(tid2,tname2)values(v_tid,v_tname);
       end if;
       commit;
       END;
    正解