我正在尝试执行我为Oracle中的数据转换而开发的脚本。
我有一个包含大量数据的表,我想根据条件将该数据拆分到另一个表中,然后从原始表中删除受影响的行。
我的方法是使用create table作为第二个表的select,然后将第二个表与第一个表相同,条件反转。最后,我截断了原始表,并将数据移回临时表中的原始数据。像这样:
create table data_reject as
select a, b, c
from table_original
where a in (select criteria from aux_table)
/
然后
create table data_aux as
select a, b, c
from table_original
where a NOT in (select criteria from aux_table)
/
最后我会做
truncate table data_original
/
和
insert into table_original (a, b, c)
select a, b, c
from table_aux
/
我的问题是我在所有select和create table命令上放置了一个并行提示,看起来发出了一条语句,下一条语句开始执行而不等待第一条语句结束执行。
这导致原始表在脚本有时间填充其他两个表之前丢失了所有数据。
使用命令
执行此脚本alter session enable parallel dml
如何阻止一个命令在前一个命令结束执行之前启动?
这是脚本的样子: - 创建临时表 create table id_loc_rejected_temp parallel 32 nologging as 同 id_hier为 (选择hierarchy7_key作为id_hierarchy中的id), loc_hier为 (选择hierarchy6_key作为loc_hierarchy的loc)
select /* + PARALLEL (a, 32) */
id_key,
loc_key
from sls a
where a.id_key not in (select key from merch_hier)
union all
select /* + PARALLEL (a, 32) */
id_key,
loc_key
from sls a
where a.loc_key not in (select store from loc_hier)
union all
select /* + PARALLEL (a, 32) */
id_key,
loc_key
from id_loc_rejected_previous a
/
insert into debug_msg values(sysdate, 'First filter. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
--add more filters
insert /* + APPEND PARALLEL (id_loc_rejected_temp, 32) */
into id_loc_rejected_temp(id_key,
loc_key)
with
store_repl as
(select /* + PARALLEL (t, 32) */ id_key as id, loc_key as store from srep t)
select /* + PARALLEL (a, 32) */
id_key,
loc_key
from sls a
where (a.id_key, a.loc_key) not in (select id, store from store_repl)
union all
select /* + PARALLEL (a, 32) */
id_key,
loc_key
from inv a
where (a.id_key, a.loc_key) not in (select id, store from store_repl)
/
insert into debug_msg values(sysdate, 'Second filter. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- remove duplicates
create table id_loc_rejected parallel 32 nologging as
select /* + PARALLEL (a, 32) */ distinct id_key, loc_key from id_loc_rejected_temp a
/
insert into debug_msg values(sysdate, 'Transformed temp table into final table. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
drop table id_loc_rejected_temp
/
insert into debug_msg values(sysdate, 'Dropped id loc rejected temp table')
/
-- Create rejected data tables
create table sls_rejected parallel 32 nologging as
select /* + PARALLEL (a, 32) */
id_key,
id_level,
loc_key,
loc_level,
date1,
ticket,
units
from sls a
where (a.id_key, a.loc_key) in (select id_key, loc_key from id_loc_rejected)
/
insert into debug_msg values(sysdate, 'Sales rejected created. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- inventory reject table
create table inv_rejected parallel 32 nologging as
select /* + PARALLEL (a, 32) */
id_key,
id_level,
loc_key,
loc_level,
date1,
ticket,
units
from inv a
where (a.id_key, a.loc_key) in (select id_key, loc_key from id_loc_rejected)
/
insert into debug_msg values(sysdate, 'Inventory rejected created. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- stockouts reject table
create table oos_rejected parallel 32 nologging as
select /* + PARALLEL (a, 32) */
id_key,
id_level,
loc_key,
loc_level,
date1,
ticket,
flag
from oos a
where (a.id_key, a.loc_key) in (select id_key, loc_key from id_loc_rejected)
/
insert into debug_msg values(sysdate, 'Stockout rejected created. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- store replenishment reject table
create table stg_ro_st_re_rejected parallel 32 nologging as
select /* + PARALLEL (a, 32) */
id_key,
loc_key,
review
from srep a
where (a.id_key, a.loc_key) in (select id_key, loc_key from id_loc_rejected)
/
insert into debug_msg values(sysdate, 'Store replenishment parameters rejected created. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- now, create temp tables to hold the rest of the data (what we want to keep)
-- sales temp table
create table sls_tmp parallel 32 nologging as
select /* + PARALLEL (a, 32) */
id_key,
id_level,
loc_key,
loc_level,
date1,
ticket,
ticket
from sls a
where (a.id_key, a.loc_key) not in (select id_key, loc_key from id_loc_rejected)
/
insert into debug_msg values(sysdate, 'Sales temp created. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- Store replenishmment temp table
create table stg_ro_store_repl_tmp parallel 32 nologging as
select /* + PARALLEL (a, 32) */
id_key,
loc_key,
review
from srep a
where (a.id_key, a.loc_key) not in (select id_key, loc_key from id_loc_rejected)
/
insert into debug_msg values(sysdate, 'Store replenishment temp created. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
-- truncate original tables and reinsert
-- Final Sales
truncate table sls
/
insert /* + APPEND PARALLEL (sls, 32) */
into sls(id_key,
id_level,
loc_key,
loc_level,
date1,
ticket,
ticket)
(
select /* + PARALLEL (a, 32) */
id_key,
id_level,
loc_key,
loc_level,
date1,
ticket,
ticket
from sls_tmp a
)
/
insert into debug_msg values(sysdate, 'Sales reinserted. Inserted ' || SQL%ROWCOUNT || ' rows')
/
commit
/
drop table sls_tmp
/
答案 0 :(得分:0)
问题在于脚本中的select语句。他们中的一些人在组织内部有空白行,这些行使得sqlplus认为它必须执行两个命令而不是一个。
这使得很长的命令完全失败,而下一个命令基本上没有任何操作或失败。
另一个问题是插入内部的SQL%ROWCOUNT
,它看起来只有一些插件正在执行而其他插件落后。
最后,我将脚本分开,一次执行一步,一切正常。