你可以在select时加上for update。
如:
select max(id)
into iMaxId
from ta_mytable
where name='大牛'
for update;
。。(一些操作)
update ta_mytable
set id=iMaxId+1
where name='大牛'
如:
select max(id)
into iMaxId
from ta_mytable
where name='大牛'
for update;
。。(一些操作)
update ta_mytable
set id=iMaxId+1
where name='大牛'
解决方案 »
- PLS-00103: 出现符号 ")"在需要下列之一时: <an identifier>
- 服务器中毒,杀毒软件杀毒后重启系统,但启动不了。系统崩溃,oracle没做备份,数据库可以恢复吗,
- ORA-01031:权限不足求教
- ORA-04021和ORA-01410错误,请高手帮忙啊
- 一个关于存储过程带返回值的问题,在线等.
- 哪位能提供 PL/SQL Developer 软件下载的?
- 在哪里可以查看在程序中用ADO发出的操作ORACLE的SQL语句
- [问题] 再请教一个Oracle中关于sql的问题?
- 触发器/函数不能读的错误
- PLSQL Developer 12 连接不上oracle
- 两张表的合并更新问题
- 请南京地区的ORACLE高手请留意!(非招聘)
如果你的ID不是要求严格+1生成的,你可以考虑用Oracle的序列,即Sequence来生成ID
存取过程在同一个时间,允许多个用户同时调用。
那么在你的select 与 update之间,只要有别的用户执行了这个过程,问题就来了。
具体你可以做实验!
语句可以通过如下方式改造
1、锁定
select max(id)
into iMaxId
from ta_mytable
where name='大牛'
for update nowait;
2、事务一致性(序列读)
set transaction isolation level serializable;
建议采用第一种方法。
并可以在过程中加入如下语句
excaption
when others then
--写日志
end;
这样的话,通过日志,你就可以知道并行情况下,发生争用的可能(也就是不加for update时可能出错的情况)
存取过程在同一个时间,允许多个用户同时调用。
那么在你的select 与 update之间,只要有别的用户执行了这个过程,问题就来了。
具体你可以做实验!
语句可以通过如下方式改造
1、锁定
select max(id)
into iMaxId
from ta_mytable
where name='大牛'
for update nowait;
2、事务一致性(序列读)
set transaction isolation level serializable;
建议采用第一种方法。
并可以在过程中加入如下语句
excaption
when others then
--写日志
end;
这样的话,通过日志,你就可以知道并行情况下,发生争用的可能(也就是不加for update时可能出错的情况)非常同意以上观点因此一定要加for update!