用before insert触发器控制:create or replace trigger trg_name on 表名 before update as ......执行状态检查
select * from table_name where ... For Update; 这样可以控制,在读取的时候其他用户是无法修改的,至于你所说得唯一读,好像没有听说过。
事务开始 update table_name set tag=1 where f=123; select xx from table_name where f=123; update table_name set tag=0 where f=123; 事务终止这么定义时,当第二个用户要访问此表,而事务还没有完成时,会在update table_name set tag=1 where f=123; 处阻塞住,直到第一个事务完成了,才回继续执行。我们有时要获取特殊流水号就是这么用的。
我觉得应该是加锁和设已读状态标志(要新加入状态标志字段)同时进行 在读取时先检查状态标志是否为零, 1.如果是0,表示未读过 select * from table_name where ... For Update;(这样可以限制在同一时刻只有一个用户可读) 然后再将读取标志置为1,表示已读 2.如果状态标志是1,则跳过
on 表名
before update
as
......执行状态检查
这样可以控制,在读取的时候其他用户是无法修改的,至于你所说得唯一读,好像没有听说过。
update table_name set tag=1 where f=123;
select xx from table_name where f=123;
update table_name set tag=0 where f=123;
事务终止这么定义时,当第二个用户要访问此表,而事务还没有完成时,会在update table_name set tag=1 where f=123; 处阻塞住,直到第一个事务完成了,才回继续执行。我们有时要获取特殊流水号就是这么用的。
在读取时先检查状态标志是否为零,
1.如果是0,表示未读过
select * from table_name where ... For Update;(这样可以限制在同一时刻只有一个用户可读)
然后再将读取标志置为1,表示已读
2.如果状态标志是1,则跳过