Skip to content

Instantly share code, notes, and snippets.

@theProgrammerDavid
Last active March 2, 2021 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theProgrammerDavid/ab0b694cd87a662dad2677c6842c2765 to your computer and use it in GitHub Desktop.
Save theProgrammerDavid/ab0b694cd87a662dad2677c6842c2765 to your computer and use it in GitHub Desktop.
Import CSV into SQLPlus
  • STEP 0. We will refer to the csv file found at https://raw.githubusercontent.com/socratica/data/master/earthquake.csv for this guide.

  • STEP 1. Ensure you have sqlldr added to path.

  • STEP 2. Ensure that your user has sufficient permissions to access/modify the required tables.

  • STEP 3a. We need to create a 'control' file which will instruct the SQLPLUS Loader on how it should load the data into the database. The SQLPLUS loader can parse most text based files.

  • STEP 3b. Create a file with the file extention of ".ctl". In this case, we will call it csv.ctl

  • STEP 3c. Enter the following lines into the file

LOAD DATA
INFILE 'D:\Programming\SQL\data\earthquake.csv'
TRUNCATE
INTO TABLE EARTHQUAKE
fields terminated by ","
(
earthquake_id,
occured_on,
latitude,
longitude,
depth,
magnitude,
calculation_method,
network_id,
place,
cause
)
  • STEP 4. Use the following command to call sqlldr
sqlldr userid=<username>/<password> control='<full path to .ctl file>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment