I’m newer to Oracle so I hope what I am trying to explain makes sense. I am required to used SQL Loader to batch load CSV files. There are about 20 organizations uploading around 15 CSV files each. Some of the files may have 10 rows, others will have thousands. The data is to be loaded into staging tables for processing at a later time.
Example CSV File:
1111_BUILDING.csv
ID,NAME,CAMPUS_ID,IMAGE_URL,STREET_ADDRESS,CITY.STATE,POSTAL_CODE,LONGITUDE,LATITUDE
183,Goss Laboratory,1,http://example.com/map/buildingImg.php?id=180,925 Coffey Rd,Columbus,OH,43210-1005,39.999997,-83.027551
The staging table for that CSV looks like the following.
CREATE TABLE "DEV"."T_STG_BUILDING"
( "ID" VARCHAR2(30 BYTE) NOT NULL ENABLE,
"NAME" VARCHAR2(255 BYTE) NOT NULL ENABLE,
"CAMPUS_ID" VARCHAR2(30 BYTE),
"IMAGE_URL" VARCHAR2(255 BYTE),
"STREET_ADDRESS" VARCHAR2(255 BYTE),
"CITY" VARCHAR2(255 BYTE),
"STATE" VARCHAR2(2 BYTE),
"POSTAL_CODE" VARCHAR2(5 BYTE),
"LONGITUDE" NUMBER(8,6),
"LATITUDE" NUMBER(8,6),
"ORGANIZATION_ID" NUMBER(10,0) NOT NULL ENABLE
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
TABLESPACE "USERS" ;
Essentially what needs to happen is the following:
Extract the ORG code from the file name. The file format is _.csv.
Then it needs to take ORG_NUMBER which in this case is 1111, look up the PK for the Organization, for sample sake lets just say it 100.
It then needs to somehow pass 100 to the SQL Loader Control file, that way it inserts 100 into the ORGANIZATION_ID column.
I hope that makes sense. Is there anyway to do this with SQL Loader? I come across an example online that showed using BASH to generate the control file on the fly but that seemed tedious and it was dated 1998.