Oracle回滚事务

Oracle数据库在添加、删除、修改时,默认没有真的提交到服务器,只是在数据的缓冲区,只有真的退出客户端,才会提交事务(生效)

1.创建一张表

SQL>create table stu
(
  sid number primary key,
  sname varchar2(15) not null,
);

2.添加三条数据

SQL> update stu set sname = ' a' where sid =1;

已更新 1 行。
SQL> update stu set sname = ' b' where sid = 2;

已更新 1 行。

SQL> update stu set sname = ' c' where sid = 3;

已更新 1 行。
3.查看数据
SQL> select * from stu;

       SID SNAME
---------- ---------------
         1  a
         2 ww
         3  c
4.操作表,commit表示提交事务,只有提交了,增删改的操作才会生效
SQL> commit;

提交完成。
SQL> delete from stu where sid = 2;

已删除 1 行。

SQL> select * from stu;

       SID SNAME
---------- ---------------
         1  a
         3  c

SQL> rollback;

回退已完成。

SQL> select * from stu;

       SID SNAME
---------- ---------------
         1  a
         2  b
         3  c


猜你喜欢

转载自blog.csdn.net/wxb52112181314/article/details/80793660