38.数据的并发处理
1.管理数据的并发
select sid,serial#,username from v$session where sid in (select blocking_session from v$session);
alter system kill session '144,8982' immediate;
--1.在一个会话中
scott@ORCL10G 2023-03-04 14:39:54> update emp set sal=sal+1 where empno = 7566;
1 row updated.
Elapsed: 00:00:00.02
scott@ORCL10G 2023-03-04 14:40:26>
--2.打开另外一个会话
scott@ORCL10G 2023-03-04 14:40:42> update emp set comm = 500 where empno = 7566;
--3.再打开一个窗口,杀掉第一次的会话
sys@ORCL10G 2023-03-04 14:42:10> select sid,serial#,username from v$session where sid in (select blocking_session from v$session);
SID SERIAL# USERNAME
---------- ---------- ------------------------------
150 134 SCOTT
Elapsed: 00:00:00.01
sys@ORCL10G 2023-03-04 14:42:45> alter system kill session '150,134' immediate;
System altered.
Elapsed: 00:00:00.05
--4.结果
----第一个会话
scott@ORCL10G 2023-03-04 14:46:17> select *from emp;
select *from emp
*
ERROR at line 1:
ORA-03135: connection lost contact
ERROR:
ORA-03114: not connected to ORACLE
Elapsed: 00:00:00.01
--第二个会话
scott@ORCL10G 2023-03-04 14:40:42> update emp set comm = 500 where empno = 7566;
1 row updated.
Elapsed: 00:01:55.07
sys@ORCL10G 2023-03-04 14:56:01> select 'alter system kill session '''||sid||','||serial#||''' immediate ;' from v$session where sid in (select blocking_session from v$session) and SECONDS_IN_WAIT > 10;
'ALTERSYSTEMKILLSESSION'''||SID||','||SERIAL#||'''IMMEDIATE;'
-------------------------------------------------------------------------------------------------------------------------
alter system kill session '146,29' immediate ;
Elapsed: 00:00:00.01
sys@ORCL10G 2023-03-04 14:56:09> alter system kill session '146,29' immediate ;
System altered.
Elapsed: 00:00:00.05