众所周知的任务:将BASICFILE LOB转换为SECUREFILE LOB。
我有一张桌子:
CREATE TABLE "DKR"."DKR_SEARCH_INFO"
( "ID" NUMBER NOT NULL ENABLE,
"REPORT" BLOB,
"CREATE_TS" TIMESTAMP (6),
"OWNER" VARCHAR2(45),
CONSTRAINT "DKR_SEARCH_INFO$PK$"
PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
LOB ("REPORT") STORE AS SECUREFILE (COMPRESS MEDIUM DEDUPLICATE) --
--
TABLESPACE WSDATA;
之后我使用SECUREFILE生成临时表DDL(来自DBMS_METADATA.GET_DDL过程):
CREATE TABLE "DKR"."DKR_SEARCH_INFO_1"
( "ID" NUMBER NOT NULL ENABLE,
"REPORT" BLOB,
"CREATE_TS" TIMESTAMP (6),
"OWNER" VARCHAR2(45),
CONSTRAINT "DKR_SEARCH_INFO$PK$_1"
PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
LOB ("REPORT") STORE AS SECUREFILE (COMPRESS MEDIUM DEDUPLICATE) --
--
TABLESPACE WSDATA;
之后我用START_REDEF_TABLE程序执行脚本:
SET serveroutput ON;
BEGIN
FOR redef_table IN
(SELECT DISTINCT dtc.owner, dtc.table_name, (LISTAGG(dtc.column_name || ' ' || dtc.column_name, ',') WITHIN GROUP (ORDER BY dtc.column_id)) AS COL_MAP
FROM dba_tab_columns dtc, dba_lobs dl
WHERE dtc.owner = dl.owner AND dtc.table_name = dl.table_name
AND dl.owner NOT IN ('APEX_030200', 'CTXSYS', 'EXFSYS', 'FLOWS_FILES', 'MDSYS', 'OLAPSYS', 'ORDDATA', 'OUTLN', 'SYS', 'SYSMAN', 'SYSTEM', 'WMSYS', 'XDB')
AND dl.partitioned = 'NO' AND dl.securefile = 'NO' AND dl.segment_created = 'YES' AND dtc.table_name = 'DKR_SEARCH_INFO'
GROUP BY dtc.owner, dtc.table_name
ORDER BY dtc.owner, dtc.table_name)
LOOP
BEGIN
DECLARE
l_col_map VARCHAR2(4000);
BEGIN
l_col_map := redef_table.col_map;
DBMS_OUTPUT.PUT_LINE(redef_table.col_map);
DBMS_OUTPUT.PUT_LINE('Owner: ' || redef_table.owner);
DBMS_OUTPUT.PUT_LINE('Table orig: ' || redef_table.table_name);
DBMS_OUTPUT.PUT_LINE('Table interim: ' || redef_table.table_name || '_1');
DBMS_OUTPUT.PUT_LINE(l_col_map);
DBMS_REDEFINITION.START_REDEF_TABLE(redef_table.owner, redef_table.table_name, redef_table.table_name || '_1', '''' || l_col_map || '''');
END;
END;
--DBMS_OUTPUT.PUT_LINE(redef_table.col_map);
END LOOP;
END;
/
我收到错误:
Error starting at line : 4 in command -
Error report -
ORA-42016: shape of interim table does not match specified column mapping
ORA-06512: на "SYS.DBMS_REDEFINITION", line 56
ORA-06512: на "SYS.DBMS_REDEFINITION", line 1498
ORA-06512: на line 21
42016. 0000 - "shape of interim table does not match specified column mapping"
*Cause: The number of columns, or the type or the length semantics of a
column, in the interim table did not match the specified
column mapping.
*Action: Ensure that the interim table matches the column mapping by
either modifying the column mapping string or altering the
interim table's column definition(s).
ID ID,REPORT REPORT,CREATE_TS CREATE_TS,OWNER OWNER
Owner: DKR
Table orig: DKR_SEARCH_INFO
Table interim: DKR_SEARCH_INFO_1
ID ID,REPORT REPORT,CREATE_TS CREATE_TS,OWNER OWNER
当我不是从脚本执行此命令时,一切正常:
DECLARE
l_col_map VARCHAR2(4000);
BEGIN
-- map all the columns in the interim table to the original table
l_col_map := 'ID ID,REPORT REPORT,CREATE_TS CREATE_TS,OWNER OWNER';
DBMS_REDEFINITION.START_REDEF_TABLE('DKR', 'DKR_SEARCH_INFO_1', 'DKR_SEARCH_INFO_1', l_col_map);
END;
/
anonymous block completed
我不明白我在脚本中犯了什么错误.. 所有在SYS用户下执行的命令。