c# - Are two UPDATE statements in same BEGIN-END block executed at the exact same time? -
if have table follows:
cid column1 1 joe 2 john
and run following code below. select statement executed (at inopportune precise millisecond half way through running of code) return column1 = john both rows in table? or oracle run both update statements in code "together" speak, never happen.
string sqlstr = @"begin update table1 set column1 = 'john' cid = 1; update table1 set column1 = 'joe' cid = 2; end;"; oracleconnection conn = new oracleconnection(oracle_connstr); oraclecommand cmd = new oraclecommand(sqlstr, conn); try { conn.open(); cmd.executenonquery(); } catch (exception ex) { } { if (cmd != null) cmd.dispose(); if (conn != null) conn.dispose(); }
the 2 update
statements run sequentially. second update
won't run until first update
finishes.
assuming 2 statements part of same transaction (which in example), other sessions prevented reading intermediate state both rows have value of "john" transaction isolation level. oracle not allow dirty reads. normally, in oracle runs in read committed transaction isolation level. means other sessions see values prior transaction starting until transaction committed @ point both statements (and else part of transaction) complete.
Comments
Post a Comment