ORA-01403:在oracle中重新定义在线表期间未找到数据 尝试将basicfile lob转换为securefile lob时。
遵循的步骤:
使用基本文件lob(存储在表空间ts1中)创建的表T1,其在数字字段上具有主键。
在表T1中加载了数据。
创建的临时表T2具有与T1相同的结构(lob是存储在表空间ts2中的Securefile)
执行在线重新定义(使用copy_indexes => 0)以将T1转换为 securefile lob。
ORA-01403:在copy_table_dependents中找不到数据。
我尝试设置copy_indexes-> 1不会导致任何错误
SQL> @online_redef.sql sf sf basic_table sf_table sf/sf@cdb1_pdb1 'sys/knl_test7@cdb1_pdb1 as sysdba' 'tbsbas.dbf' 'tbsinter.dbf'
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL>
SQL> SHOW CON_NAME
CON_NAME
------------------------------
CDB1_PDB1
SQL>
SQL>
SQL> -- Create a new user
SQL> DROP USER &1 CASCADE;
old 1: DROP USER &1 CASCADE
new 1: DROP USER sf CASCADE
DROP USER sf CASCADE
*
ERROR at line 1:
ORA-01918: user 'SF' does not exist
SQL> CREATE USER &1 IDENTIFIED BY &2;
old 1: CREATE USER &1 IDENTIFIED BY &2
new 1: CREATE USER sf IDENTIFIED BY sf
User created.
SQL>
SQL> -- Grant privileges
SQL> GRANT EXECUTE ANY PROCEDURE TO &1;
old 1: GRANT EXECUTE ANY PROCEDURE TO &1
new 1: GRANT EXECUTE ANY PROCEDURE TO sf
Grant succeeded.
SQL> GRANT CONNECT, RESOURCE, CREATE SESSION TO &1;
old 1: GRANT CONNECT, RESOURCE, CREATE SESSION TO &1
new 1: GRANT CONNECT, RESOURCE, CREATE SESSION TO sf
Grant succeeded.
SQL> GRANT CREATE TABLESPACE, ALTER TABLESPACE, UNLIMITED TABLESPACE, DROP TABLESPACE TO &1;
old 1: GRANT CREATE TABLESPACE, ALTER TABLESPACE, UNLIMITED TABLESPACE, DROP TABLESPACE TO &1
new 1: GRANT CREATE TABLESPACE, ALTER TABLESPACE, UNLIMITED TABLESPACE, DROP TABLESPACE TO sf
Grant succeeded.
SQL> GRANT SELECT ANY SEQUENCE TO &1;
old 1: GRANT SELECT ANY SEQUENCE TO &1
new 1: GRANT SELECT ANY SEQUENCE TO sf
Grant succeeded.
SQL>
SQL>
SQL> -- Connect as user
SQL> CONNECT &5
Connected.
SQL>
SQL>
SQL> -- Create tablespace for storage of BasicFiles
SQL> DROP TABLESPACE &3 INCLUDING CONTENTS AND DATAFILES;
old 1: DROP TABLESPACE &3 INCLUDING CONTENTS AND DATAFILES
new 1: DROP TABLESPACE basic_table INCLUDING CONTENTS AND DATAFILES
DROP TABLESPACE basic_table INCLUDING CONTENTS AND DATAFILES
*
ERROR at line 1:
ORA-00959: tablespace 'BASIC_TABLE' does not exist
SQL> CREATE TABLESPACE &3
2 DATAFILE '&7'
3 SIZE 256M REUSE
4 EXTENT MANAGEMENT LOCAL
5 UNIFORM SIZE 4M
6 SEGMENT SPACE MANAGEMENT AUTO;
old 1: CREATE TABLESPACE &3
new 1: CREATE TABLESPACE basic_table
old 2: DATAFILE '&7'
new 2: DATAFILE 'tbsbas.dbf'
Tablespace created.
SQL>
SQL>
SQL> -- Create tablespace for storage of interim table.
SQL> DROP TABLESPACE &4 INCLUDING CONTENTS AND DATAFILES;
old 1: DROP TABLESPACE &4 INCLUDING CONTENTS AND DATAFILES
new 1: DROP TABLESPACE sf_table INCLUDING CONTENTS AND DATAFILES
DROP TABLESPACE sf_table INCLUDING CONTENTS AND DATAFILES
*
ERROR at line 1:
ORA-00959: tablespace 'SF_TABLE' does not exist
SQL> CREATE TABLESPACE &4
2 DATAFILE '&8'
3 SIZE 256M REUSE
4 EXTENT MANAGEMENT LOCAL
5 UNIFORM SIZE 4M
6 SEGMENT SPACE MANAGEMENT AUTO;
old 1: CREATE TABLESPACE &4
new 1: CREATE TABLESPACE sf_table
old 2: DATAFILE '&8'
new 2: DATAFILE 'tbsinter.dbf'
Tablespace created.
SQL>
SQL> --Translate BasicFile to SecureFile
SQL> CREATE OR REPLACE PROCEDURE TranslateBasicToSecure( schemaName IN VARCHAR2,
2 originalTableName IN VARCHAR2, interimTableName IN VARCHAR2) IS
3 redefinition_errors PLS_INTEGER := 0;
4 BEGIN
5 -- Check whether table can be redefined
6 DBMS_OUTPUT.PUT_LINE('Checking if table can be redefined');
7 DBMS_REDEFINITION.CAN_REDEF_TABLE(schemaName, originalTableName);
8
9 -- Attempt a redefinition mapping.
10 DBMS_OUTPUT.PUT_LINE('Attempting to start redefinition');
11 DBMS_REDEFINITION.START_REDEF_TABLE (
12 uname => schemaName,
13 orig_table => originalTableName,
14 int_table => interimTableName,
15 col_mapping => NULL,
16 options_flag => DBMS_REDEFINITION.CONS_USE_PK
17 );
18
19 -- Copy data
20 DBMS_OUTPUT.PUT_LINE('Copying table dependents');
21 DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS (
22 uname => schemaName,
23 orig_table => originalTableName,
24 int_table => interimTableName,
25 copy_indexes => 0,
26 copy_triggers => TRUE,
27 copy_constraints => TRUE,
28 copy_privileges => TRUE,
29 ignore_errors => FALSE,
30 num_errors => redefinition_errors,
31 copy_statistics => FALSE,
32 copy_mvlog => FALSE
33 );
34
35 IF (redefinition_errors > 0) THEN
36 DBMS_OUTPUT.PUT_LINE('Migration errors: '
37 || TO_CHAR(redefinition_errors));
38 END IF;
39
40 DBMS_OUTPUT.PUT_LINE('Sync Interim Table');
41 DBMS_REDEFINITION.SYNC_INTERIM_TABLE(schemaName,
42 originalTableName, interimTableName);
43
44 -- Complete the redefinition process
45 DBMS_OUTPUT.PUT_LINE('Finish redefinition process');
46 DBMS_REDEFINITION.FINISH_REDEF_TABLE (
47 uname => schemaName,
48 orig_table => originalTableName,
49 int_table => interimTableName
50 );
51
52 EXCEPTION
53 WHEN OTHERS THEN
54 DBMS_OUTPUT.PUT_LINE('Exception Caught!!');
55 DBMS_OUTPUT.PUT_LINE('Error : ' || SQLCODE || ' - ' || SQLERRM);
56 DBMS_REDEFINITION.ABORT_REDEF_TABLE (
57 uname => schemaName,
58 orig_table => originalTableName,
59 int_table => interimTableName
60 );
61
62 END;
63 /
Procedure created.
SQL> SHOW ERRORS;
No errors.
SQL>
SQL>
SQL>
SQL> -- Create sequence to generate unique id's
SQL> DROP SEQUENCE seq;
DROP SEQUENCE seq
*
ERROR at line 1:
ORA-02289: sequence does not exist
SQL> CREATE SEQUENCE seq;
Sequence created.
SQL>
SQL>
SQL> -- Table containing BasicFile
SQL> DROP TABLE &3 PURGE;
old 1: DROP TABLE &3 PURGE
new 1: DROP TABLE basic_table PURGE
DROP TABLE basic_table PURGE
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> CREATE TABLE &3 (
2 cnt NUMBER,
3 cdata CLOB,
4 bdata BLOB,
5 prevcmb VARCHAR2(500),
6 currentcmb VARCHAR2(500),
7 id NUMBER DEFAULT seq.NEXTVAL
8 )
9 LOB(cdata)
10 STORE AS BASICFILE (TABLESPACE &3),
11 LOB(bdata)
12 STORE AS BASICFILE (TABLESPACE &3),
13 PARTITION BY RANGE (cnt)
14 SUBPARTITION BY HASH(id)
15 SUBPARTITIONS 8 STORE IN (&3, &3, &4, &4)
16 (PARTITION p1 VALUES LESS THAN (20),
17 PARTITION p2 VALUES LESS THAN (40),
18 PARTITION p3 VALUES LESS THAN (60));
old 1: CREATE TABLE &3 (
new 1: CREATE TABLE basic_table (
old 10: STORE AS BASICFILE (TABLESPACE &3),
new 10: STORE AS BASICFILE (TABLESPACE basic_table),
old 12: STORE AS BASICFILE (TABLESPACE &3),
new 12: STORE AS BASICFILE (TABLESPACE basic_table),
old 15: SUBPARTITIONS 8 STORE IN (&3, &3, &4, &4)
new 15: SUBPARTITIONS 8 STORE IN (basic_table, basic_table, sf_table, sf_table)
Table created.
SQL>
SQL>
SQL> ALTER TABLE &3 ADD CONSTRAINT PK_BASIC PRIMARY KEY(cnt);
old 1: ALTER TABLE &3 ADD CONSTRAINT PK_BASIC PRIMARY KEY(cnt)
new 1: ALTER TABLE basic_table ADD CONSTRAINT PK_BASIC PRIMARY KEY(cnt)
Table altered.
SQL>
SQL>
SQL> -- Table containing LOBs stored as SecureFile
SQL> DROP TABLE &4 PURGE;
old 1: DROP TABLE &4 PURGE
new 1: DROP TABLE sf_table PURGE
DROP TABLE sf_table PURGE
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> CREATE TABLE &4 (
2 cnt NUMBER,
3 cdata CLOB,
4 bdata BLOB,
5 prevcmb VARCHAR2(500),
6 currentcmb VARCHAR2(500),
7 id NUMBER DEFAULT seq.NEXTVAL
8 )
9 LOB(cdata)
10 STORE AS SECUREFILE (TABLESPACE &4),
11 LOB(bdata)
12 STORE AS SECUREFILE (TABLESPACE &4),
13 PARTITION BY RANGE (cnt)
14 SUBPARTITION BY HASH(id)
15 SUBPARTITIONS 8 STORE IN (&3, &3, &4, &4)
16 (PARTITION p1 VALUES LESS THAN (20),
17 PARTITION p2 VALUES LESS THAN (40),
18 PARTITION p3 VALUES LESS THAN (60));
old 1: CREATE TABLE &4 (
new 1: CREATE TABLE sf_table (
old 10: STORE AS SECUREFILE (TABLESPACE &4),
new 10: STORE AS SECUREFILE (TABLESPACE sf_table),
old 12: STORE AS SECUREFILE (TABLESPACE &4),
new 12: STORE AS SECUREFILE (TABLESPACE sf_table),
old 15: SUBPARTITIONS 8 STORE IN (&3, &3, &4, &4)
new 15: SUBPARTITIONS 8 STORE IN (basic_table, basic_table, sf_table, sf_table)
Table created.
SQL>
SQL>
SQL> -- Populate table containing BasicFile
SQL> DECLARE
2 cnt NUMBER;
3 dataBlob BLOB;
4 BEGIN
5 FOR cnt in 1..5 LOOP
6 INSERT INTO &3(cnt,cdata,bdata) VALUES (cnt,
7 dbms_random.string('a', round(dbms_random.value(low=>10,high=>4000))),
8 EMPTY_BLOB())
9 RETURNING bdata INTO dataBlob;
10 LoadBFile('T_WORK', 'tklolobdata.dmp', dataBlob);
11 END LOOP;
12 END;
13 /
old 6: INSERT INTO &3(cnt,cdata,bdata) VALUES (cnt,
new 6: INSERT INTO basic_table(cnt,cdata,bdata) VALUES (cnt,
PL/SQL procedure successfully completed.
SQL> SHOW ERRORS;
No errors.
SQL> COMMIT;
Commit complete.
SQL>
SQL> SELECT COUNT(*) FROM &3;
old 1: SELECT COUNT(*) FROM &3
new 1: SELECT COUNT(*) FROM basic_table
COUNT(*)
----------
5
1 row selected.
SQL>
SQL> CONN &6
Connected.
SQL> SET SERVEROUTPUT ON
SQL>
SQL> SELECT SECUREFILE FROM dba_lobs WHERE table_name = upper('&3');
old 1: SELECT SECUREFILE FROM dba_lobs WHERE table_name = upper('&3')
new 1: SELECT SECUREFILE FROM dba_lobs WHERE table_name = upper('basic_table')
SEC
---
NO
NO
2 rows selected.
SQL>
SQL>
SQL> -- Translate table containing BasicFile to SecureFile
SQL> exec TranslateBasicToSecure('&1','&3','&4');
Checking if table can be redefined
Attempting to start redefinition
Copying table dependents
Exception Caught!!
Error : 100 - ORA-01403: no data found
PL/SQL procedure successfully completed.
SQL>
SQL> -- Verify if table is copied
SQL> SELECT SECUREFILE FROM dba_lobs WHERE table_name = upper('&3');
old 1: SELECT SECUREFILE FROM dba_lobs WHERE table_name = upper('&3')
new 1: SELECT SECUREFILE FROM dba_lobs WHERE table_name = upper('basic_table')
SEC
---
NO
NO
2 rows selected.
SQL> SQL>
预期结果:Basicfile lob将转换为Securefile lob。
实际结果:错误:100-ORA-01403:未找到数据 重新定义后,表的dba_lobs中的SECUREFILE字段为“否”
答案 0 :(得分:0)
您可以做一个完整的演示吗?我无法复制您的错误。这是我的自上而下
SQL> create table T1 ( x int, y clob, t timestamp default systimestamp, constraint T1_PK primary key (x) )
2 lob (y) store as basicfile ( tablespace users );
Table created.
SQL>
SQL> insert into t1 (x,y)
2 select rownum, rpad(rownum,4000)
3 from dual
4 connect by level <= 100;
100 rows created.
SQL> commit;
Commit complete.
SQL>
SQL> create table T2 ( x int, y clob, t timestamp default systimestamp )
2 lob (y) store as securefile ( tablespace largets );
Table created.
SQL>
SQL> EXEC DBMS_REDEFINITION.can_redef_table(user, 'T1');
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_REDEFINITION.start_redef_table(user, 'T1', 'T2');
PL/SQL procedure successfully completed.
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 l_num_errors PLS_INTEGER;
3 BEGIN
4 DBMS_REDEFINITION.copy_table_dependents(
5 uname => user,
6 orig_table => 'T1',
7 int_table => 'T2',
8 copy_indexes => DBMS_REDEFINITION.cons_orig_params,
9 copy_triggers => TRUE, -- Default
10 copy_constraints => TRUE, -- Default
11 copy_privileges => TRUE, -- Default
12 ignore_errors => FALSE, -- Default
13 num_errors => l_num_errors);
14 DBMS_OUTPUT.put_line('l_num_errors=' || l_num_errors);
15 END;
16 /
l_num_errors=0
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_REDEFINITION.sync_interim_table(user, 'T1', 'T2');
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_REDEFINITION.finish_redef_table(user, 'T1', 'T2');
PL/SQL procedure successfully completed.
SQL>