创建DIRECTORY目录

create or replace directory dump_dir as 'D:\dmp\dump_dir'

创建用户并授权

create user test identified by 123;
grant read,write on directory dump_dir to test; --只能导出表
grant dba to test; --可以导出表、模式、表空间、全库

1、导出MAO.门急诊诊疗处方表,MAO.门急诊诊疗挂号记录表

expdp test/123@192.168.0.177:1521/hisyb directory=dump_dir dumpfile=tab.dmp logfile=tab_export.log tables=MAO.门急诊诊疗处方表,MAO.门急诊诊疗挂号记录表

查询test用户下的所有表

值用单引号括起来再用,分隔
select ''''||LISTAGG(table_name,''',''') within group (order by table_name)||'''' from dba_tables where owner='TEST';

值仅用,分隔
select LISTAGG(table_name,',') within group (order by table_name) from dba_tables where owner='TEST';

2、导出模式

expdp test/123@192.168.0.177:1521/hisyb directory=dump_dir dumpfile=schema.dmp logfile=schema_export.log schemas=mao

3、导出表空间

expdp test/123@192.168.0.177:1521/hisyb directory=dump_dir dumpfile=tablespace.dmp logfile=tablespace_export.log tablespaces=trasen

查看表空间的使用情况  

SELECT a.tablespace_name,  
round(a.bytes / (1024 * 1024), 0) total,
round(b.bytes / (1024 * 1024), 0) used,
round(c.bytes / (1024 * 1024), 0) free
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
WHERE a.tablespace_name = b.tablespace_name
AND a.tablespace_name = c.tablespace_name;

4、导出全数据库

expdp test/123@192.168.0.177:1521/hisyb directory=dump_dir dumpfile=fulldatabase.dmp logfile=fulldatabase_export.log full=y


1、导入表(将dmp文件中的MAO.门急诊诊疗处方表导入HU模式中)

impdp test/123@192.168.0.177:1521/hisyb table_exists_action=replace directory=dump_dir dumpfile=tab.dmp logfile=tab_import.log tables=MAO.门急诊诊疗处方表 remap_schema=MAO:HU

table_exists_action参数说明(导入时,若表已经存在)

1)  skip:默认操作
2) replace:先drop表,然后创建表,最后插入数据
3) append:在原来数据的基础上增加数据
4) truncate:先truncate,然后再插入数据

2、导入模式(将MAO模式中的所有对象导入HU模式中)

impdp test/123@192.168.0.177:1521/hisyb table_exists_action=replace  directory=dump_dir dumpfile=schema.dmp logfile=schema_import.log schemas=scott remap_schema=MAO:HU

3、导入表空间(将trasen表空间中的所有对象都导入到当前数据库中)

impdp test/123@192.168.0.177:1521/hisyb directory=dump_dir dumpfile=tablespace.dmp logfile=tablespace_import.log tablespaces=trasen

4、导入全数据库(从fulldatabase.dmp文件导入全数据库)

impdp test/123@192.168.0.177:1521/hisyb directory=dump_dir dumpfile=fulldatabase.dmp logfile=fulldatabase_import.log full=y