我想在数据插入之前,先truncate掉表里的内容。
于是做了一个触发器由它来调用一个存储过程,
create or replace trigger on_time
before insert on nodetime
Begin
truntable(); End;
/create or replace procedure truntable
is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
execute immediate 'truncate table nodetime';
commit;
end;
/由于触发器里不能有commit;所以在过程里使用了自治事物。
但运行起来还是出问题。LException: ORA-00054: 资源正忙,要求指定 NOWAIT在"ATM.TRUNTABLE", line 5
在"ATM.ON_NODETIME", line 3
触发器 'ATM.ON_NODETIME' 执行过程中出错
于是做了一个触发器由它来调用一个存储过程,
create or replace trigger on_time
before insert on nodetime
Begin
truntable(); End;
/create or replace procedure truntable
is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
execute immediate 'truncate table nodetime';
commit;
end;
/由于触发器里不能有commit;所以在过程里使用了自治事物。
但运行起来还是出问题。LException: ORA-00054: 资源正忙,要求指定 NOWAIT在"ATM.TRUNTABLE", line 5
在"ATM.ON_NODETIME", line 3
触发器 'ATM.ON_NODETIME' 执行过程中出错
所以'truncate table nodetime'是不行的.只能用 delete from nodetime
表nodetime里本来存储有数据,
在新的数据插入到nodetime之前,
我想先清除掉nodetime里以前的所有数据。
我用delete from nodetime 的话是可以但nodetime里
始终只有一条数据,是怎么回事?
就像是批量替换。比如 nodetime表里本来有50条数据,
在新的数据插入之前,先删除这50条数据,然后再插入新
的数据,而不是插入一条数据就执行一次删除操作。
用存储过程。
create or replace procedure inserttab
is
begin
execute immediate 'truncate table nodetime';
insert into tab;
插入数据。
commit;
end;
/