在频繁使用的表上将现有列更改为“not null”时,我希望避免出现以下或任何其他错误消息:
SQL Error: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
00054. 00000 - "resource busy and acquire with NOWAIT specified or timeout expired"
*Cause: Interested resource is busy.
*Action: Retry if necessary or increase timeout.
我的 Oracle 版本是:Oracle Database 12c 企业版版本 12.1.0.2.0 - 64 位生产版。我尝试使用独占锁,如下所示,但仍然收到错误。我通过在其他 session 中执行一些 DML 来模拟一个频繁使用的表。
第 1 节
create table iei1731 (
col1 varchar2(1 char),
col2 number(1,0)
);
insert into iei1731 (col1, col2) values ('1', 0);
commit;
update iei1731 set col1 = col1 where col1 = '1';
第二节
lock table iei1731 in exclusive mode;
第 1 节
rollback; -- now session 2 gets the exclusive lock on the table
update iei1731 set col1 = col1 where col1 = '1';
第二节
alter table iei1731 modify col2 not null; -- here I get the ORA-00054
第 1 节(清理)
rollback;
drop table iei1731;
所以我的问题是是否有可能将这个频繁使用的表上的列设置为非空而不出现任何错误消息?
最佳答案
使用DDL_LOCK_TIMEOUT让 session 等待锁定:
--Wait up to 10 minutes to acquire the lock.
alter session set DDL_LOCK_TIMEOUT=600;
alter table iei1731 modify col2 not null;
关于sql - 将列更改为非空时避免 ORA-00054,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45145974/