我已经使用 Oracle DBMS pkg 进行并行执行,并且工作正常。
现在我正在尝试使用来运行一个简单的 MERGE stmt。它给了我各种各样的错误。我尝试了相同的 pkg create_chunks_by_rowid 和 create_chunks_by_number_col 所有这些错误。
我的问题是它(DBMS_PARALLEL_EXECUTE pkg)可以处理合并stmt还是我做错了什么? 如有任何帮助,我们将不胜感激。
顺便说一句,合并 sql stmt 在 sql 中运行时运行良好。
下面给出的是我尝试使用的合并 stmt,并从 pkg 中获取错误。
CREATE TABLE test_tab (
id NUMBER,
description VARCHAR2(50),
num_col NUMBER,
session_id NUMBER,
CONSTRAINT test_tab_pk PRIMARY KEY (id)
);
INSERT /*+ APPEND */ INTO test_tab
SELECT level,
'Description for ' || level,
CASE
WHEN MOD(level, 5) = 0 THEN 10
WHEN MOD(level, 3) = 0 THEN 20
ELSE 30
END,
SYS_CONTEXT(''USERENV'',''SESSIONID'')
FROM dual
CONNECT BY level <= 1000000;
COMMIT;
create table test_tab2 as select * from test_tab;
delete from test_tab where rownum<500001;
commit;
exec DBMS_PARALLEL_EXECUTE.drop_task (task_name => 'test_task');
exec DBMS_PARALLEL_EXECUTE.create_task (task_name => 'test_task');
SELECT DBMS_PARALLEL_EXECUTE.generate_task_name
FROM dual;
set serverout on;
DECLARE
l_stmt varchar2(32767);
BEGIN
l_stmt := 'MERGE into test_tab2 b
using test_tab a
on (a.id=b.id)
when matched then
update set b.session_id = a.session_id
when not matched then
insert (id,description,num_col,session_id)
values(a.id,a.description,a.num_col,a.session_id)';
DBMS_PARALLEL_EXECUTE.create_chunks_by_sql(task_name => 'test_task',
sql_stmt => l_stmt,
by_rowid => FALSE);
END;
/
Error report -
ORA-01007: variable not in select list
ORA-06512: at "SYS.DBMS_PARALLEL_EXECUTE", line 373
ORA-06512: at "SYS.DBMS_SQL", line 1641
ORA-06512: at "SYS.DBMS_PARALLEL_EXECUTE", line 324
ORA-06512: at line 13
01007. 00000 - "variable not in select list"
*Cause:
*Action:
不要使用那个包,它太麻烦了。只需启用并行 dml 并提示查询即可:
BEGIN
EXECUTE IMMEDIATE 'alter session enable parallel dml';
MERGE /*+ parallel(16) append */ into test_tab2 b
using test_tab a
on (a.id=b.id)
when matched then
update set b.session_id = a.session_id
when not matched then
insert (id,description,num_col,session_id)
values(a.id,a.description,a.num_col,a.session_id);
COMMIT;
END;