java_Oralce
简单范例
create or replace procedure delete_table
is
i number(10);
begin
for x in (select * from emp where DEPTNO like 'a%')
loop
delete emp where emp.id = x.id
i:=i+1;
if i>1000 then
commit;
i:=0;
end if;
end loop;
exception
when others then
dbms_out.put_line(sqlcode);
rollback;
end delete_table;
Oracle中删除超过50w条记录的数据,如果直接使用delete,效率就严重受到了影响。那么首先我们需要了解对于这个表的数据,我们到底是全部删除,还是部分删除。这里有三个关键字我们需要注意:truncate,delete,drop,他们之间的异同点可以参考这篇文章——truncate,delete,drop的异同点。
全部删除,不保留数据结构就直接drop最好。如果是部分删除,一般就这样一些办法:
1. 如果删除的数据是大部分,分段提交删除的数据。
| create or replace procedure delete_table is i number(10); begin for x in (select * from emp where DEPTNO like ‘a%’) loop delete emp where emp.id = x.id i:=i+1; if i>1000 then commit; i:=0; end if; end loop; exception when others then dbms_out.put_line(sqlcode); rollback; end delete_table; |
或者
|
–每500条数据提交一次 |
2、把要保留的数据放在一个临时表里,truncate table原表后再放回来;
| create table t_back as select * from t where …. drop table t; rename t_back to t; |
3. 专门使用一个大回滚段 ,比如定义:undo tablespace 2G
4、如果将方法1做一点修改,可以这么做:
|
有条件的分步删除数据表中的记录 –创建测试表 –创建删除表的存储过程 –插入语句 –执行语句 |
java_Oralce的更多相关文章
随机推荐
- Selenium IDE验证点
Selenium IDE验证点 我们还开发了测试用例需要检查一个Web页面的属性.这需要维护和验证命令.有两种方法可以验证点到任何脚本 插入记录模式中的任何验证点单击“右键”元素,并选择“Show a ...
- 获取本机外网IP的方式笔记
1.IP138 网址:http://www.ip138.com/: 分离出的快速查询地址:http://20140507.ip138.com/ic.asp(2014年8月9日有效) 个人经验:百度搜索 ...
- android:照片涂画功能实现过程及原理
这个功能可以帮你实现,在图片上进行随意的涂抹,可以用于SNS产品. 绘图本身很简单,但是要实现在图片上指定的部分精确(位置,缩放)的绘图,就有点麻烦了. 下面讲讲实现过程及原理: UI构图 这个UI, ...
- bzoj 1009 [HNOI2008]GT考试(DP+KMP+矩阵乘法)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1009 [题意] 给定一个字符串T,问长度为n且不包含串T的字符串有多少种. [思路] ...
- sys.check_constraints
每个用作 CHECK 约束(sys.objects.type = C)的对象都在表中占一行. SELECT name FROM sys.check_constraints -- equal to SE ...
- NetAdvantage 笔记
1.UltraControlBase Class Members 1.BeginUpdate Method Sets the IsUpdating flag to true which prevent ...
- openstack配置增加
控制节点nova配置增加 vif_plugging_is_fatal = Falsevif_plugging_timeout = 0scheduler_default_filters = AllHos ...
- HDU 5680 zxa and set (数学 推导结论)
zxa and set 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/G Description zxa has a set , ...
- Spring MVC SimpleUrlHandlerMapping example
In Spring MVC application, the SimpleUrlHandlerMapping is the most flexible handler mapping class, w ...
- HTTP Header 简介
HTTP Header 简介 HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服 ...