
事务就是一系列的 *** 作,要么同时完成,要么不完成
都是由一个dml语句开始的
updata emp2 set sal=sal*2
delete from dept2
insert into salgrade values (6,10000,20000)
//这样是一个transaction语句,如果使用rollback返回,则上面三条语句将不起任何作用
transaction语句的结束为 1.rollback transaction语句结束.
2.commit提交完成,transaction语句结束
3.执行ddl,或则dcl语句事务自动提交.
4.当用户正常断开连接时,transcation自动提交
5.当用户非正常断开连接时,Oracle自动执行rollback语句
如:select * from dept2//transcation开始
create table t (a varchar2(20))//执行了ddl语句,则transcation语句自动提交
sqlserver:begin try
begin tran
update 1
update 2
end tran
commit tran
end try
begin catch
rollback tran
end catch
以oracle自带的scott为例:1、select
t1.ename,t2.ename
as
mgrname,d.dname
from
scott.emp
t1,scott.emp
t2,scott.dept
d
where
t1.mgr=t2.empno
and
t2.deptno=d.deptno
2、select
d.*
from
scott.dept
d,(select
rownum
n,
tt.*
from
(select
count(*)
c,deptno
from
scott.emp
group
by
deptno
order
by
c
desc)
tt)t
where
t.n=1
and
t.deptno=d.deptno
3、select
*
from(select
t.*,dense_rank()over
(partition
by
deptno
order
by
sal)
r
from
scott.emp
t
where
deptno=30)
where
r<=3
4、select
*
from(select
t.*,rank()over
(partition
by
n
order
by
sal)
r
from
(select
''
as
n,tt.*
from
scott.emp
tt)
t)
where
r
between
5
and
10
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)