您的位置:首页 > 数据库 > Oracle

Oracle export and import data

2016-10-18 21:16 549 查看
Oracle support 2 types of data export/import

1. Utility exp/imp

     -- But data format is binary, people cannot read and write them.

2. Using sqlplus/sqlldr

     -- Export data as text file,  and import as text file also.

Following is a sample using sqlplus/sqlldr to export and import a table.

Suppose table is defined as:

SQL> desc KSDS09;

Name                                     Null?    Type

------------------------------------------------- ----------------------------

KSDS09_SEQ_NUM                            NOT NULL NUMBER(8)

K_NUM                                     NOT NULLNUMBER(6)

K_NUM02                                   NOT NULL NUMBER(2)

K_X                                       NOT NULL CHAR(22)

D01                                               VARCHAR2(30)

REC0_END0                                         CHAR(4)

(e.g., export DB_LOGIN=scott/tiger@orcl)

-- Export script:

sqlplus -s ${DB_LOGIN} >/dev/null<<EOF

set heading off;

set echo off;

set feedback off;

set verify off;

set wrap off;

set pagesize 0;

set linesize 2500;

set trimout on;

set trimspool on;

set trims on;

spoolKSDS09.txt;

selectKSDS09_SEQ_NUM || ',' || K_NUM || ',' || K_NUM02 || ',' || K_X || ',' || D01 ||',' || REC0_END0 from KSDS09;

set define on;

set heading on;

set echo on;

set feedback on;

spool off;

quit;

EOF

-- Import script:

   step 1: define sqlldr control file

  $ catKSDS09.ctl

  load data                

  infile'KSDS09.txt'

  appendinto table KSDS09H

  fields terminated by ","

  (KSDS09_SEQ_NUM, K_NUM, K_NUM02, K_X, D01,REC0_END0)

   step 2: execute sqlldr command

   sqlldr userid=${DB_LOGIN}control=KSDS09.ctl

-- Appendix: data in KSDS09.text

$ head KSDS09.txt

1,10,1,AAAA        ,ABCD                              ,1234

2,10,2,BBBB         ,ABCD                              ,1234

3,10,3,CCCC         ,ABCD                              ,1234

...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: