IMP cross-platform Migration Database SQL generation SQL method tablespace creation script, impsql
When using EXP/IMP for cross-platform migration, we need to manually create the tablespace and data files consistent with the source at the target end due to the tablespace path change, the following is the script used to create the statement.
1. Run the following command in the source database to generate the creation script
select 'create tablespace ' || b.NAME || ' DATAFILE ' || chr(39) || a.NAME || chr(39) || ' SIZE ' || a.BYTES / 1024 / 1024 || ' m;' from v$datafile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='YES'Union Allselect 'Create Temporary Tablespace ' || b.NAME || ' Tempfile ' || chr(39) || a.NAME ||chr(39) || ' SIZE ' || a.BYTES / 1024 / 1024 || ' m;' from v$tempfile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='NO'Union Allselect 'alter database datafile ' ||chr(39) ||a.NAME ||chr(39)||' autoextend on ;' from v$datafile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='YES'Union Allselect 'alter database Tempfile ' ||chr(39) ||a.NAME ||chr(39)||' autoextend on ;' from v$tempfile a, v$tablespace bwhere a.ts# = b.TS# And b.INCLUDED_IN_DATABASE_BACKUP='NO'
II. The generated results are similar to the following: Example:
Create tablespace system datafile '/oradata/orcl/system01.dbf' size 1000 m;
Create tablespace undotbs1 datafile '/oradata/orcl/undotbs01.dbf' size 1630 m;
Create tablespace sysaux datafile '/oradata/orcl/sysaux01.dbf' size 1000 m;
Create tablespace users datafile '/oradata/orcl/users01.dbf' size 5 m;
......
Create tablespace zl9indexdev datafile '/oradata/orcl/zl9indexdev. dbf' size 20 m;
Create tablespace zl9humanbase datafile '/oradata/orcl/zl9humanbase. dbf' size 20 m;
Create tablespace zl9humaninfo datafile '/oradata/orcl/zl9humaninfo. dbf' size 20 m;
.......
Alter database datafile '/oradata/orcl/system01.dbf' autoextend on;
Alter database datafile '/oradata/orcl/undotbs01.dbf' autoextend on;
Alter database datafile '/oradata/orcl/sysaux01.dbf' autoextend on;
Alter database datafile '/oradata/orcl/users01.dbf' autoextend on;
......
Alter database tempfile '/oradata/orcl/zltoolstmp. dbf' autoextend on;
Modify the path of the data file of the statement generated by replacing the statement, execute the command on the target end, generate the tablespace and data file, and then import the data.