我在空表中写存储过程
create or replace procedure p
is
i number:=1;
cursor c is select id from sun_t;
begin
for v_c in c
loop
exit when(i=10);
if(c%rowcount<>0)then
insert into sun_t(id) values (0);
--update sun_t set id=test_s.nextval,name='test rowcount' where current of c;
dbms_output.put_line(c%rowcount);
end if;
i:=i+1;
end loop;
commit;
end p;
为什么一行记录也没插入?????
c%rowcount<>0我改成
c%rowcount=0
c%rowcount is null
c%rowcount is not null
都不行????

解决方案 »

  1.   

    如果sun_t表是空表,那么cursor c就不会有数据,那么for v_c in c就不会成了,自然不会执行里面的操作了。
      

  2.   

    说得不错,空表的话,执行下面这句
    cursor c is select id from sun_t; 
    得出的游标cursor c为空,而你后面又用这个游标来取数据,当然取不到数据,那么插入也就为空了!sun_t表里没有数据了
      

  3.   


    TRY TO CHANGE IT AS BELOW:..
    IF C%FOUND THEN
    ..
      

  4.   

    可以改成 sql%rowcount来统计上次sql语句 执行影响的行数