lorcx 2016-04-10 02:12 采纳率: 46.7%
浏览 1474

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次 这才是正常结果为什么

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 虚心请教几个问题,小生先有礼了
    • ¥30 截图中的mathematics程序转换成matlab