oracle 存储过程中使用游标
2013-10-24 10:42
323 查看
项目上准备线,使用存储过程进行基础数据的初始化(有则更新,无则插入)。
1、建立临时表 temp;
2、前台上传文件,写入临时表 temp;
3、通过存储过程,处理temp数据,初始化。
使用游标循环处理临时表数据,进行数据的插入与更新。
begin
for mycus in cus loop
begin
insert table ...
end;
end loop;
for mycus2 in cus2 loop
begin
update table ...
end;
end loop;
end;
使用上面的方式,即先插入新数据,再更新。会影响游标cus2的结果集,导致数据重复更新。因为游标是在打开的时候,才根据定义,查询结果集。所以insert(update)都会影响后面的结果集。
在不影响初始化数据时,应现在更新操作,在插入新数据。
begin
for mycus2 in cus2 loop
begin
update table ...
end;
end loop;
for mycus in cus loop
begin
insert table ...
end;
end loop;
end;
1、建立临时表 temp;
2、前台上传文件,写入临时表 temp;
3、通过存储过程,处理temp数据,初始化。
使用游标循环处理临时表数据,进行数据的插入与更新。
begin
for mycus in cus loop
begin
insert table ...
end;
end loop;
for mycus2 in cus2 loop
begin
update table ...
end;
end loop;
end;
使用上面的方式,即先插入新数据,再更新。会影响游标cus2的结果集,导致数据重复更新。因为游标是在打开的时候,才根据定义,查询结果集。所以insert(update)都会影响后面的结果集。
在不影响初始化数据时,应现在更新操作,在插入新数据。
begin
for mycus2 in cus2 loop
begin
update table ...
end;
end loop;
for mycus in cus loop
begin
insert table ...
end;
end loop;
end;
相关文章推荐
- oracle中存储 过程嵌套游标的使用
- ORACLE 存储过程使用技巧&游标技巧
- oracle存储过程中游标的使用
- oracle 存储过程和游标的使用
- oracle之存储过程6- if、for、游标使用
- Oracle存储过程中如何使用游标
- oracle存储过程之insert的使用,含游标的使用
- Oracle存储过程中使用游标来批量解析CLOB字段里面的xml字符串:
- Oracle与MySQL存储过程以及游标使用的区别
- oracle存储过程中 使用游标做循环封装数据集
- Oracle 存储过程中使用cursor 游标遍历数据
- oracle 存储过程中使用游标
- oracle中建表、游标、存储过程的使用方法入门
- Oracle存储过程使用游标遍历
- oracle存储过程:游标使用,多重游标
- oracle 存储过程之游标(loop)使用
- Oracle中加密解密的数据库函数,创建(包含游标)和使用存储过程
- Oracle 存储过程中使用cursor 游标遍历数据
- oracle使用游标 触发器的存储过程
- oracle存储过程中使用Ref Cursor强类型游标返回结果集