Oracleデータインポート・エクスポート
- Thu
- 22:58
- Oracle
Oracleのインポート/エクスポート
単にタブ区切りでデータを取得したい場合などに。
まずは、データの取得(export)
sqlldr用のctlファイル
imp.ctl
データインポート用の実行スクリプト
単にタブ区切りでデータを取得したい場合などに。
まずは、データの取得(export)
#!/bin/sh USER_PASS=user/pass@db sqlplus $USER_PASS <<EOF set echo off; set heading off; set wrap off; set linesize 999; set serveroutput on; spool $HOME/tmp/exp.tsv; BEGIN DBMS_OUTPUT.ENABLE_(NULL); FOR r IN ( SELECT col1 , col2 , col3 FROM test_tbl ) LOOP DBMS_OUTPUT.PUT_LINE ( r.col1 || CHR(9) || r.col2 || CHR(9) || r.col3 ); END LOOP; END; / exit; EOF #### EOF
sqlldr用のctlファイル
imp.ctl
load data infile '$HOME/tmp/exp.tvs' append into table test_tbl fields terminated by X'09' trailing nullcols ( col1 , col2 , col3 )
データインポート用の実行スクリプト
#!/bin/sh USER_PASS=user/pass@db sqlplus $USER_PASS <<EOF DROP TABLE test_tbl; CREATE TABLE test_tbl; col1 NUMBER , col2 VARCHAR2(10) , col3 VARCHAR2(10) ); exit; EOF sqlldr $USER_PASS COLTROL=$HOME/tmp/imp.ctl #### EOF