imp导入切换表空间

 在工作中遇到了一个问题,imp导入的时候需要切换用户的表空间,简略记一下

 
方法其实很简单(并且此方法也可以用于其它不同的问题,很有用处):
 
需要先用dbms_metadata得到要导入表的ddl,然后重新生成改变表空间的ddl语句,再来imp导入时即可
 
下面写一个例子
###########################################################################
 
[oracle@lcrash ~]$ sqlplus scott/tiger
 
SQL> select table_name,tablespace_name from user_tables;
 
TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
DEPT                           USERS
BONUS                          USERS
EMP                            USERS
SALGRADE                       USERS
TEST                           USERS
TEST1                          USERS
 
删除scott用户所有的表
再修改为scott用户的默认表空间为新建的scott表空间
 
SQL> create tablespace scott datafile '/opt/oracle/oradata/lc/scott.dbf' size 10M
  2  extent management local segment space management auto
  3  /
 
Tablespace created.
 
SQL> alter user scott default tablespace scott;
 
利用plsql修改表的默认表空间为scott,下面是一个例子
CREATE TABLE "SCOTT"."BONUS" 
   ("ENAME" VARCHAR2(10), 
"JOB" VARCHAR2(9), 
"SAL" NUMBER, 
"COMM" NUMBER
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE " SCOTT" ;
......
  
[oracle@lcrash ~]$ imp scott/tiger file=scott.dmp ignore=y
 
[oracle@lcrash ~]$ usqlplus scott/tiger
 
SQL> select table_name,tablespace_name from user_tables;
 
TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
DEPT                           SCOTT
BONUS                          SCOTT
EMP                            SCOTT
SALGRADE                       SCOTT
TEST                           SCOTT
TEST1                          SCOTT
 
至此发现导入的表空间已经不是users而是scott了
 
###########################################################################
 

你可能感兴趣的:(职场,imp,休闲,空间)