IMP数据到指定的表空间

来源:互联网 发布:马前课指算法日加时 编辑:程序博客网 时间:2024/04/30 22:47

  一直以来,我都认为只要指定用户的默认表空间,向该用户导入数据时,会自动进入到默认表空间。后来发现从System导出的dmp文件在导入时,即使指定新用户的默认表空间,还是要往System表空间中导数据。

上网搜了一下,还是有解决方法的,常见的方法如下:

SQL> create user myhuang identified by myhuang default tablespace myhuang;

SQL> grant resource,connect to myhuang;

SQL> grant dba to myhuang;//DBA权限

SQL> revoke unlimited tablespace from myhuang;//撤销此权限

SQL> alter user myhuang quota 0 on system;//将用户在System表空间的配额置为0

SQL> alter user myhuang quota unlimited on myhuang;//设置在用户在myhuang表空间配额不受限。

 

经过上述设置后,就可以用imp导入数据,数据将会进入指定的myhuang表空间:

C:/Documents and Settings/myhuang>imp system/123456@vdb fromuser=lnxh tous

er=myhuang file=G:/myhuang/lnxh.dmp ignore=y grants=n

 

顺便说两个小问题:

1IMP-00003: 遇到 ORACLE 错误 1658

ORA-01658: 无法为表空间 MYHUANG 中的段创建 INITIAL

通常这个问题可以通过Resize增加表空间数据文件大小来解决。

 

2)删除表空间

SQL> drop tablespace myhuang including contents and datafiles;

10g中实验,drop表空间之后,仍然需要手动去删除数据文件。

 
//2008-08-24补充————————————————————————
另一种比较好的方法:

Create tablespace {tbs_name} datafile ‘{file_path}’ size 500M autoextend on next 10M;

Create user {u_name} identified by {u_pwd} default tablespace {tbs_name} quota unlimited on {tbs_name};

Grant connect,imp_full_database to {u_name};

Imp {u_name}/{u_pwd}@{local_svrname} fromuser={from_user} touser={u_name} file={dmp_file_path} ignore=y tablespaces={tbs_name};

此方法不需要授予新用户DBA权限。
此方法的存在的问题是:可能导致包含BLOB、CLOB字段的表导入失败,这种情况下可以先用sql脚本将表结构建立起来,再导入相应的数据。

原创粉丝点击