oracle存储过程使用游标的问题

create or replace procedure test3(
templete_id in varchar2
) as
t_id_tmp varchar2(50);
ty_id_tmp varchar2(50);
cursor type_cur is select t1.id as type_id,t1.type_name from t_type t1,t_templete_link t2,t_templete t3
where t1.id = t2.type_id and t2.templete_id = t3.id and t3.id = templete_id;
-- n number;
begin
select sys_guid() into t_id_tmp from dual;

 --复制模板信息
 insert into t_templete
 select t_id_tmp as id, t.templete_name
   from t_templete t
  where t.id = templete_id;
 commit;      

   dbms_output.put_line(templete_id); 
 --复制类别信息
-- declare 

 begin
   for type_rec in type_cur
     loop
        -- n:=n+1;
        -- dbms_output.put_line(1);        
         select sys_guid() into ty_id_tmp from dual;       
         insert into t_type
           select ty_id_tmp as id, type_rec.type_name from dual;
            -- from t_type t2
          --  where t2.id = type_rec.type_id;
         --  commit;   

          insert into t_templete_link   
              select sys_guid() as id,t_id_tmp as TEMPLETE_ID ,ty_id_tmp as type_id from dual; -- t_templete_link t2
              --where t2.templete_id = templete_id;
          commit;    
       end loop;
   end;

--dbms_output.put_line(t_id_tmp);

exception
  when others then
    Rollback;

end test3;

如果我传入的参数templete_id=1,我的t_cur循环的时候循环了3次。
但如果游标中的变变量templete_id 替换成 ‘1’就循环2次 这才是正常结果为什么

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问