I'm attempting to add a nullable column 开发者_运维知识库to a frequently used table in an Oracle 10 OLTP database while the application is running and busy. Adding a nullable column is only a data dictionary change and therefore any table lock is only held for a short period of time (which can be handled by the system).
The problem is that my ALTER TABLE
often fails with this:
ORA-00054: resource busy and acquire with NOWAIT specified
My current approach is to bludgen the change in by running it until there happens to be no locks on the table. This means I can't run such a script in SQL*Plus in full, but need to copy and paste each statement and make sure it works.
Is there a better way?
How about a brute force approach? Put it in an infinite loop and exit it when done. Pseudocode(haven't checked it):
create or replace
procedure execDDL(ddl in varchar2) is
myexp EXCEPTION;
pragma exception_init (myexp, -54);
begin
loop
begin
execute immediate ddl;
exit;
exception
when myexp then
null;
end loop;
end;
精彩评论