如何使用可序列化事务隔离在 PL/SQL 中运行查询

Moh*_*yan 0 oracle oracle-11g transaction isolation-level plsql-developer

我想在 Oracle 11g 中运行这个 SQL:

declare a number;
  begin 
  select count(*) into a  from item w where w.Item_num='MOH601' ; 
  dbms_output.put_line(a);
  end ; 
Run Code Online (Sandbox Code Playgroud)

如何使用隔离可序列化运行此查询?正如我之前所了解的,Oracle 会w.Item_num='MOH601'在使用 Serializable 时锁定行。

Phi*_*lᵀᴹ 5

更改会话:

declare a number;
  begin 
    EXECUTE IMMEDIATE 'ALTER SESSION SET ISOLATION_LEVEL SERIALIZABLE';
    select count(*) into a  from item w where w.Item_num='MOH601' ; 
    dbms_output.put_line(a);
  end ; 
Run Code Online (Sandbox Code Playgroud)