Oracle批量逐条数据处理
2017-05-09 17:00
197 查看
----批量逐条数据处理模版-----
create or replace procedure proc_test is
batch_size constant pls_integer := 1000;--批量处理数量
--定义结果集数组
type data_result is record(
tn_column1 tablename.column1%type,
tn_column2 tablename.column4%%type,
tn_column3 varchar2(4000));
type data_result is varray(1000) of data_result;--数组大小
results data_result;
--定义游标
cursor cur_curname is
select column1, column2, column3, column14
from (select t.column1,
t.column2,
t.column3,
wm_concat(t.column4) column4 --列转行
from tablename t
group by t.column1, t.column2, t.column3)
where length(column4) > 2;
begin
open cur_curname; --打开游标
loop
fetch cur_curname bulk collect
into results limit batch_size;
for i in 1 .. results.count loop --逐条处理
--业务逻辑处理
dbms_output.put_line(results.count);
end loop;
exit when cur_curname%notfound;
end loop;
--关闭游标
if cur_curname%isopen then
close cur_curname;
end if;
commit;
exception
when others then
dbms_output.put_line('error : ' || sqlcode || '--' || sqlerrm);
rollback;
end;
create or replace procedure proc_test is
batch_size constant pls_integer := 1000;--批量处理数量
--定义结果集数组
type data_result is record(
tn_column1 tablename.column1%type,
tn_column2 tablename.column4%%type,
tn_column3 varchar2(4000));
type data_result is varray(1000) of data_result;--数组大小
results data_result;
--定义游标
cursor cur_curname is
select column1, column2, column3, column14
from (select t.column1,
t.column2,
t.column3,
wm_concat(t.column4) column4 --列转行
from tablename t
group by t.column1, t.column2, t.column3)
where length(column4) > 2;
begin
open cur_curname; --打开游标
loop
fetch cur_curname bulk collect
into results limit batch_size;
for i in 1 .. results.count loop --逐条处理
--业务逻辑处理
dbms_output.put_line(results.count);
end loop;
exit when cur_curname%notfound;
end loop;
--关闭游标
if cur_curname%isopen then
close cur_curname;
end if;
commit;
exception
when others then
dbms_output.put_line('error : ' || sqlcode || '--' || sqlerrm);
rollback;
end;
相关文章推荐
- Oracle 逐条和批量插入数据方式对比
- Oracle 逐条和批量插入数据方式对比
- Oracle 逐条和批量插入数据方式对比
- Oracle批量生成测试数据方法
- oracle批量绑定的概念
- oracle 使用游标批量分段插入数据
- oracle批量绑定 forall bulk collect用法以及测试案例
- oracle 批量重建索引
- 如何在Oracle中批量删除数据
- Oracle中的Merge函数(批量更新/删除)【转】
- 如何在Oracle中批量插入数据
- 简单的NHibernate helper类,支持同一事务的批量数据处理
- ORACLE批量导出sequence
- ORACLE 和SQLSERVER 两表之间批量更新数据对比
- 如何更快地批量数据处理?
- 一种动态构建PLSQL包进行批量数据处理的方法
- Struts 1.x中批量封装对象,多行数据处理两种方法
- .net中利用oracle产品自带的数据访问组件(Oracle.DataAccess.dll)提升批量更新操作的执行效率
- Oracle中如何批量重命名带有小写字母的表名
- Oracle批量创建用户和导入导出的脚本