有一个表叫t_user
字段 c_code 下有一些工号
如 1111 2222 3333 44444 08074926
还有个表 xht_111 空的。下边是个过程
declare
cursor aa is
select u.c_code as v_code from t_user u;
begin
  savepoint a;
for data1 in aa loop
insert into xht_111 values(data1.v_code);
if data1.v_code='08074926' then
rollback to a;
end if;
end loop;
commit;
end;这个例子的构想是如果 c_code 有工号是08074926 的话,
那就应该回滚到初始啊~
为啥还是会插入数据呢

解决方案 »

  1.   

    怀疑那条记录c_code值后面有空格或者不可显示字符。把这一句修改成这样试试:
    cursor aa is
    select rtrim(u.c_code) as v_code from t_user u;要不看看
    select * from t_user where c_code = '08074926';是否可以返回记录。
      

  2.   

    SQL> select * from a05;C_CODE
    --------------------
    1111
    2222
    3333
    44444
    08074926SQL> select * from a06;no rows selectedSQL>
    SQL>
    SQL> select * from a05;C_CODE
    --------------------
    1111
    2222
    3333
    44444
    08074926SQL> select * from a06;no rows selectedSQL> declare
      2    cursor aa is
      3      select u.c_code as v_code from a05 u;
      4  begin
      5    savepoint a;
      6    for data1 in aa loop
      7      insert into a06 values (data1.v_code);
      8      if data1.v_code = '08074926' then
      9        rollback to a;
     10      end if;
     11    end loop;
     12    commit;
     13  end;
     14  /PL/SQL procedure successfully completed.SQL> select * from a06;no rows selectedSQL>测试没问题。
    楼上分析的在理
      

  3.   

    多谢楼上2位朋友,非常感谢select * from t_user where c_code = '08074926';是可以返回记录的。。
    我又按照2楼朋友方式 重新测试下,还不可以是不是 需要什么命令开启事物回滚啊。。
      

  4.   

    首先不知道你定义的c_code字段是什么类型的,number or varchar2,建议你可以先检查一下你数据库里面存的是08074926 还是 8074926,有可能是这个引起的。
      

  5.   

    按照2楼jdsnhan 的方法 重新建立了表 居然可以。。我那个就不可以,,,百思不得其解
    4楼朋友
    select * from t_user where c_code = '08074926';是可以返回记录的。。
    用的是vchar2(255)
      

  6.   

    问题找到了哈表c_code 
    数据 111 222 44 08074926 33 555
    过程之后 就是33 555
    数据 111 222 44 33 555 08074926 过程之后 就无
      

  7.   

    又有个问题表c_code  
    字段如下
    111
    222
    33
    08074926
    55
    66
    怎么样可以使08074926 排到最后一位呢