Skip to content

junlapong/oracle-bulk-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Oracle

Requirement

  1. rename import_table to import_table_YYYYMMDD
  2. create empty import_table
  3. sqlldr import.csv to import_table

Example

@echo off

SET PRJ_DIR=c:\db-import
SET RENAME_SCRIPT=%PRJ_DIR%\sql\rename_table.sql
SET CSV_FILE=%PRJ_DIR%\csv\import.csv
SET CTL_FILE=%PRJ_DIR%\ctl\import.ctl
SET LOG_FILE=%PRJ_DIR%\logs\import.log

::SET TODAY=20200527
set TODAY=%date:~10,4%%date:~4,2%%date:~7,2%
echo %TODAY%
SET TABLE_NAME=import_table
SET RENAME_SQL=RENAME %TABLE_NAME% TO %TABLE_NAME%_%TODAY%;
echo %RENAME_SQL% > %RENAME_SCRIPT%

:: ----------------------------------------
SET DB_USER=
SET DB_PASS=
SET DB_NAME=
:: ----------------------------------------

echo exit | sqlplus %DB_USER%/%DB_PASS%@%DB_NAME% @%RENAME_SCRIPT%

echo sqlldr userid=%DB_USER%/%DB_PASS%@%DB_NAME% data=%CSV_FILE% control=%CTL_FILE% log=%LOG_FILE%

@echo on

References

exit | sqlplus user/pass@yourdb @scriptname
exit | sqlplus -s -l user/pass@yourdb @yoursql.sql > your_log.log
LOAD DATA
INFILE test.dat
INTO TABLE test
FIELDS TERMINATED BY '|'
(i, s)

กรณีรวมไฟล์ Control กับ Data ไว้ในไฟล์เดียวกัน ใช้สัญลักษณ * เข้ามาแทนที่ ดังตัวอย่าง

LOAD DATA
INFILE *
INTO TABLE foo
FIELDS TERMINATED BY '|'
(i, d DATE 'dd-mm-yyyy')
BEGINDATA
1|01-01-1990
2|4-1-1998

ตัวอย่าง

sqlldr username@server/password control=loader.ctl log=log.txt

Docker Image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published