Hello. I have a folder that contains multiple json files. I need to load the contents of each file into a single CLOB column in a table using SQL Loader. Each file will be a separate row in the table.
Ideally, inserting the following files would give me a table with three rows where JSON_DATA contains the data from the file.
foldername/
file1.json
file2.json
file3.json
Here is the table info:
CREATE TABLE "JSON_DATA"
(
"JSON_DATA" CLOB
)
The following control file loads the first character (i.e. '{') of each json file and that is it. I need the entire file loaded.
--ctl file
LOAD DATA
INFILE 'foldername/*.json'
TRUNCATE
INTO TABLE JSON_DATA
(HE_JSON_DATA)
This problem seems pretty straightforward, but everything I've tried doesn't work.
SQL*Loader has these defaults:
TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
This means it considers double quotes to be the start/end of fields. Given there are almost certainly double quotes somewhere in the JSON fields, this is a problem!
To get around this specify your own values for the terminator characters! e.g.:
FIELDS TERMINATED BY '##'
If the JSON documents are formatted/split over many lines you'll need further work to combine them into one. One way is with the LOBFILE option
https://asktom.oracle.com/pls/apex/f?p=100:11:::::P11_QUESTION_ID:627223659651