我现在有游标c_cursorRoom ,查询出的结果,当做游标c_cursor 的参数进行查询,然后再执行新增动作。我直接用游标2的sql语句select id,c_m_id from s_table1 where c_m_id<>'0000' and c_template_id='123';查询出数据库中结果才20条,但放到游标中执行,就上百条。不知道那里搞错了,麻烦给指点下。谢谢declare
cursor c_cursorRoom
is select id,c_template_id from s_table1 where c_m_id='0000';
cursor c_cursor (temPId varchar2)
is select id,c_m_id from s_table1 where c_m_id<>'0000' and c_template_id<=temPId ;
v_destTblId s_table1.id%type;
v_mmroomId s_table1.id%type;
v_PtableId s_table1.id%type;
v_PtempId s_table1.c_template_id%type;
vCount number(10):=0;
vCount_out number(10):=0;
begin open c_cursorRoom;
fetch c_cursorRoom into v_PtableId,v_PtempId;
while c_cursorRoom%Found loop
vCount_out :=vCount_out+1;
open c_cursor(temPId =>v_PtempId);
fetch c_cursor into v_destTblId,v_mmroomId;
while c_cursor%Found loop
insert into s_table2 values(sys_guid(),'0000',v_PtempId,v_PtableId,v_mmroomId,v_destTblId);
vCount := vCount+1;
fetch c_cursor into v_destTblId,v_mmroomId;
end loop;
close c_cursor;
fetch c_cursorRoom into v_PtableId,v_PtempId;
end loop;
dbms_output.put_line('--vCount:'||to_char(vCount)||':'||vCount_out);
close c_cursorRoom;
end;
cursor c_cursorRoom
is select id,c_template_id from s_table1 where c_m_id='0000';
cursor c_cursor (temPId varchar2)
is select id,c_m_id from s_table1 where c_m_id<>'0000' and c_template_id<=temPId ;
v_destTblId s_table1.id%type;
v_mmroomId s_table1.id%type;
v_PtableId s_table1.id%type;
v_PtempId s_table1.c_template_id%type;
vCount number(10):=0;
vCount_out number(10):=0;
begin open c_cursorRoom;
fetch c_cursorRoom into v_PtableId,v_PtempId;
while c_cursorRoom%Found loop
vCount_out :=vCount_out+1;
open c_cursor(temPId =>v_PtempId);
fetch c_cursor into v_destTblId,v_mmroomId;
while c_cursor%Found loop
insert into s_table2 values(sys_guid(),'0000',v_PtempId,v_PtableId,v_mmroomId,v_destTblId);
vCount := vCount+1;
fetch c_cursor into v_destTblId,v_mmroomId;
end loop;
close c_cursor;
fetch c_cursorRoom into v_PtableId,v_PtempId;
end loop;
dbms_output.put_line('--vCount:'||to_char(vCount)||':'||vCount_out);
close c_cursorRoom;
end;
解决方案 »
- 求一与count, distinct相关的view.
- 问个多表关联分类汇总统计的问题,谢谢
- Oracle 简单存储过程的问题。。。 在线等。。。
- 如何不换行输出?
- 请高手指教START WITH CONNECT BY的问题?
- 在RedHat9中oracle9i安装时.installer启动后,界面无法显示中文.
- 数据库导入导出的问题(紧急!!!),高分奉送
- SQL小考
- 请问,OPEN_CURSORS一般设为多少比较合理?或者有什么标准来设这个数字?
- oracle密码到期,会导致sqluld2无法导出数据么?
- oracle中查询blob数据类型
- Oracle数据库中SYS.XMLTYPE类型子内容查询的问题
循环中间也有: fetch c_cursorRoom into v_PtableId,v_PtempId; 。还有其他的循环游标方式吗
v_destTblId 这个变量在执行插入操作时用到了。
insert into s_table2 values(sys_guid(),'0000',v_PtempId,v_PtableId,v_mmroomId,v_destTblId);
还有就是我也不理解为什么 要fetch2次。我看一个教程上就时这么写的。
量太多也就一个游标,分批提交。