ORACLE-数据导出、导入

  • 以spool方式导出文本数据
SET feedback off
SET newpage none
SET pagesize 50000
SET linesize 20000
SET verify off
SET pagesize 0
SET term off
SET trims ON
SET heading off
SET trimspool ON
SET trimout ON
SET timing off
SET verify off
SET colsep |
spool d:\dataexp\tableName.txt
    select SERIAL_ID || ',' || TSSH_SERIAL_NO || ',' || SERVICE_FIELD || ',' || SERVICE_TYPE || ',' || CHANNEL_TYPE || ',' || PROVINCE_CODE || ',' || SOURCE_AREA || ',' || to_char(ACCEPT_TIME,'yyyymmddHH24miss') || ',' || to_char(REPLY_TIME,'yyyymmddHH24miss') || ',' || CALL_TYPE || ',' || to_char(FINISH_TIME,'yyyymmddHH24miss') || ',' || to_char(VISIT_TIME,'yyyymmddHH24miss') || ',' || TITLE || ',' || CONTENT || ',' || STATUS || ',' || ACCEPT_SATISFACTION || ',' || HANDLE_RESULT || ',' || HANDLE_SATISFACTION || ',' || VISIT_SATISFACTION || ',' || to_char(CREATE_TIME,'yyyymmddHH24miss') || ',' || NOTE || ',' || REPLY_FLAG || ',' || SERVICE_ITEM || ',' || WAIT_TIME || ',' || CALL_ID || ',' || CALL_NO || ',' || OPER_CODE || ',' || to_char(RING_TIME,'yyyymmddHH24miss') || ',' || to_char(START_TIME,'yyyymmddHH24miss') || ',' || to_char(END_TIME,'yyyymmddHH24miss') from table_name where length(content) > 10 and rownum < 100001 order by serial_id desc;
spool off
  • 使用expdp(数据泵)方式导出数据.(服务器端导出)
1. 先使用sqlplus登陆
    sqlplus / as sysdba;
2. 在sqlplus命令行,创建导出数据存放目录
    create directory expDir as '/home/oracle/dataexp/expDir';
   查看管理员目录
    select * from dba_directories;
3. 在sqlplus命令行,把存放目录授权给导出用户
    grant read,write on directory expDir to tssh;
4. 退出sqlplus命令行,使用系统命令expdp使用用户模式导出整个用户下的数据
    expdp user/pwd schemas=orcl directory=expDir dumpfile=exp_file.dmp logfile=exp_file.log job_name=my_job
    
    directory 参数需要放在前面,否则会出现错误
    job_name 参数最后不需要加 ; ,否则job_name就会带 ;
  • 使用exp(普通)方式导出数据.(客户端导出)
1. 在cmd(或者linux命令行)执行以下语句
    exp userid=user/pwd@orcl full=y file=exp_file.dmp log=exp_file.log
  • 使用imp(普通)方式导入数据.
1. 对于oracle11g,需要执行以下语句,否则空表不导入
    alter system set deferred_segment_creation=false;
2. 在cmd(或者linux命令行)执行以下语句
    imp userid=user/pwd@orcl full=y ignore=y file=exp_file.dmp log=exp_file.log
  • 导出实例
1. 按条件精确导出某条数据[导出指定ID数据]
    expdp user/pwd directory=expDir dumpfile=exp_file.dmp logfile=exp_file.log  TABLES=TABLE_NAME QUERY=TABLE_NAME:\"WHERE SERIAL_ID = 100000005776\"
2. 按指定时间导出数据[导出7月份数据]
    expdp user/pwd directory=expDir dumpfile=TABLE_NAME_201707.dmp logfile=exp_file.log  TABLES=TABLE_NAME QUERY=TABLE_NAME:\"WHERE to_char\(CREATE_TIME, \'yyyy/mm\'\) = \'2017/06\'\"
3. 采用并行方式导出
    expdp user/pwd directory=expDir dumpfile=exp_file_%U.dmp logfile=exp_file.log  TABLES=TABLE_NAME QUERY=TABLE_NAME:\"WHERE SERIAL_ID = 100000005776\" parallel=10
  • 导入实例
1. 导入表数据,表已存在增量导入
impdp user/pwd directory=expDir dumpfile=user_data_201706.dmp logfile=exp_file_201706.log TABLES=TABLE_NAME,TABLE_NAME_2 table_exists_action=APPEND
2. 采用并行方式导入
impdp user/e6mu3Z03 directory=expDir dumpfile=user_data_all_20170905_%U.dmp logfile=user_data_all_imp_20170905.log table_exists_action=APPEND parallel=10

-- schema 变更
impdp IISP/iisp REMAP_SCHEMA=user:IISP directory=expdir dumpfile=exp_177_season3_%U.dmp logfile=imp_177_data.log table_exists_action=APPEND parallel=10
  • 参考资料
  1. 数据泵方式导数据
    http://blog.csdn.net/haiross/article/details/27580199/
  2. 日期转换
    http://www.cnblogs.com/lslvxy/p/3457049.html

你可能感兴趣的:(ORACLE-数据导出、导入)