上下文: Oracle DB (plsql)
现在我有了这个程序,我们称之为main。在主内,我只是检查一些数据的完整性。
如果一切正常,我调用第二个过程(在main中),调用import。
将临时表中的插入数据导入历史表(而不提交它为)。
在导入内部,我会捕获任何异常。
最后,导入返回一个布尔值,如果成功与否,进程返回到main。
主要检查输入是否正确,如果正确,则调用第三个过程stats。
现在提问:
是否可能stats不查看导入所做的更改?我的意思是,stats知道导入到历史表中的新数据?
“伪码”:
主程序
select count(*) into var1
from table1;
if var1 == 0 then
storedprocedure_import(result);
if (result) = true then
storedprocedure_stats(result);
end if;
end if;
导入过程
insert /*+ append */ into table_history
select *
from table_temporary;
STAT过程
for tmp_data in (select distinct(data) dta
from table_history
order by dta)
loop
delete from stats_table
where data = tmp_data.dta;
insert into stats_table
select tmp_data.dta, count(*) unique_stb
from table_history
where tmp_data.dta = table_history.data
group by table_history.data;
end loop;
现在我对此有点怀疑
insert into stats_table
select tmp_data.dta, count(*) unique_stb
from table_history
where tmp_data.dta = table_history.data
group by table_history.data;
因为我不确定在调用stats的地方,它知道导入导入的table_history内部的新日期
发布于 2016-11-23 11:26:05
正如Boneist所提到的,所有过程都在同一个事务中运行(除非您用pragma automomous_transaction
指定了另一种方式,但我们不去那里)。
我怀疑导入过程中存在由于insert /*+ append */
造成的问题,因为在对表进行任何操作(包括查询表)之前,必须提交直接路径操作,这是您的统计过程尝试执行的。这可能是失败的,并且异常被您的自定义错误处理程序隐藏。
create table demo (c int);
insert /*+ append */ into demo select 1 from dual;
1 row created.
select count(*) from demo;
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
正如tbone所提到的,只有在批量加载数千万行时,insert /*+ append */
才是有用的。
https://stackoverflow.com/questions/40745690
复制相似问题