===========================
1.transaction control
默认由修改数据开始(tx_lock),手工:set transaction |dbms_transaction
由commit,rollback结束(rollback to savepoin不会结束transaction)
a)默认statement-level atomicity 如
savepoint statement1;
insert into t values(1);
if error then rollback to statement1;
savepoint statment2;
insert into t values(2);
if error then rollback to statement2;
b)procedure level atomicity
begin
proce1;
end; 等价于
begin
savepoint sp;
proce1;
exception when others then
rollback to sp;
end;
保持procedure操作一致性
=======
当手动写
begin
proce1;
exception when others then
null;--则回到statement-level,错误不处理
end;
2.transaction习惯
a)尽量短
b)大业务切割成定期(比如1000个)分批提交
c)
--创建index
create index i_wwm on twwm(object_name);
exec dbms_stats.gather_table_stats('SYS','TWWM',cascade => true);
--非自动增长undo(多次commit并不节省undo tablespace)
create undo tablespace undo_small
datafile 'd:\1.dbf' size 2m
autoextend off;
--使用
alter system set undo_tablespace=undo_small;
begin
for r in(select rowid rid,rownum rnum,object_name from twwm) loop--置于for循环
update twwm set object_name=lower(r.object_name) where rowid=r.rid;
if(mod(r.rnum,100)=0) then
commit;
end if;
end loop;
commit;
end;
3.distributed transactions
一个transaction可以连接多个数据库db_link
4.自治transactions(内部transaction),不影响外部
pragma autonomous_transaction (编译指示)
set timing off
select sq_aaa.nextval from dual默认用到autonomous transactions,不能会回滚
----------
create or replace procedure Autonomous_Insert
as
pragma autonomous_transaction;
begin
insert into t values('Autonomous Insert');--内部事务
commit;
end;
begin
insert into t values('Anonymous Block');
Autonomous_Insert;--内部commit不对外部影响
rollback;
end;
-----------------------------
create table audit_tab(
username varchar2(30) default user,
timestamp date default sysdate,
msg varchar2(4000)
);
create or replace trigger t_emp_audit
before update on emp for each row
declare
pragma autonomous_transaction;
i_cnt number;
begin
select count(*) into i_cnt from dual
where exist(select null from emp where empno=:new.empno
start with mgr=(select empno from emp where ename=user)
connect by prior empno=mgr;
if(i_cnt=0) then
insert into audit_tab(msg) values('Attempt to update '||new.empno);
commit;--提交不受外部影响
raise_application_error(-20001,'Access Deniedd!');
end if;
end;
b)pragma automomous_transaction用在方法,函数中
savepoint a; rollback to a;可支持精确点
savepoint回滚之后的预计,保留savepoint,其后的savepoint删除;释放该锁,之前的锁保留;
c)对update,delete可能出现的锁
for update...nowait
分享到:
相关推荐
分布式事务学习笔记,总结的很好,希望可以帮助学习者!
XTS支付宝分布式事务学习指南汇编.pdf
- 了解分布式事务产生的原因 - 知道几种分布式事务解决方案:XA、TCC、消息事务、TA、SAGA - 知道分布式事务各种解决方案的优缺点和使用场景 - 学会使用Seata来解决分布式事务
关于mysql事务的学习,包含一个一个PPT讲解,以及相应的几个案例源码。
分布式事务就是指事务的参与者、支持事务的服务器、资源服务器以及事务管理器分别位于不同的分布式系统的不同节点之上。简单的说,就是一次大的操作由不同的小操作组成,这些小的操作分布在不同的服务器上,且属于...
该源码对应第三节的每个小节,可以自行下载学习,也方便我之后的回顾!!
spring学习事务源码spring学习事务源码spring学习事务源码spring学习事务源码spring学习事务源码spring学习事务源码spring学习事务源码spring学习事务源码
易语言学习进阶事务处理源码,学习进阶事务处理
事务是逻辑上的一组操作,组成这组操作的各个单元,要不全都成功要不全都失败,这个特性就是事务,下面就是关于MySQL事务学习中的心得分享: 事务的特性 1.原子性(Atomicity):原子性是指事务是一个不可分割的工作...
支付宝大规模SOA系统中的分布式事务处理_程立_SD2C2008.pdf
使用JOTM完成多数据源事务管理 在上一篇文档《Spring事务学习文档 》中,在最后我们说到了有两种方法来解决分布式事务,接下来,我们就简单说一下如何使用JOTM来管理分布式事务。
如果你有对触发器和事务的概念,有些了解,这篇文章,对你来说会是很简单,或能让你更进一步的了解触发器里面的一些故事,和触发器中事务个故事。在这边文章里面,我不会从触发器和事务的概念去讲述,而是从常见的两...
本文来自于csdn,本文主要从分布式的原因,事务特性,和解决方案中深入理解了分布式事务,希望对您的学习有所帮助。 分布式事务就是指事务的参与者、支持事务的服务器、资源服务器以及事务管理器分别位于不同的...
学习律师事务所管理办法学习心得.docx
会计师事务所学习培训协议范本全新梳理版.pdf
易语言学习进阶事务处理源码。@资源源码站。
Oracle学习笔记(事务知识点),事务处理:所谓的事务处理其实就是保证数据操作的完整性,所有的操作要么同时成功,要么同时失败
分布式事务解决方案Seata 框架学习代码 Demo 。里面包含了完成的seata使用代码,包括AT、TCC、XA等模式的直接使用案例。开箱即用。 分布式事务解决方案Seata 框架学习代码 Demo 。里面包含了完成的seata使用代码,...
事务和并发控制学习教案 事务和并发控制是计算机科学中两个重要的概念,它们都是为了解决多用户访问同一个资源时可能出现的问题。在本学习教案中,我们将学习事务和并发控制的概念、特点和实现方法。 一、事务 ...