SQLLDR -- selective loading from pipe delimited txt - oracle

I am looking for a way to do selective loading using SQLLDR.
The source file is in "pipe delimited" format.
I know there is a way for this if the source is in a predefined position. It is explained here, by using WHEN & POSITION keywords.
What could I do if the source file is "pipe or tab" delimited?

I am not sure what you mean with "selective loading"?
But ify you are only asking how you can load a file where each column is delimited with a pipe, then use the option FIELDS TERMINATED BY '|' in the control file.
See the chapter "Variable Record Format" in the SQL*Loader manual for more details and examples:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_concepts.htm#sthref476

Depending on which version of the SQLLDR version you are using, you can use the keyword FILLER to skip a field from the file.
The below instruction will skip the second field in the file.
LOAD DATA
TRUNCATE INTO TABLE T1
FIELDS TERMINATED BY ','
( field1,
field2 FILLER,
field3
)

LOAD DATA
INFILE 'c:\myfile.txt'
TRUNCATE INTO TABLE T1
FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS (field1, field2 , field3, field4)

Related

External Table Help - Problem with FIELDS TERMINATED BY ',' if additional comma exists in a value in the field

I have a comma delimited txt file and I am using an external table to load the data down below:
create table test_ext_table
CUSTOMER_ID NUMBER,
CUSTOMER_NAME VARCHAR2(255),
CUSTOMER_NUMBER NUMBER)
ORGANIZATION EXTERNAL
( type oracle_loader
default directory TXT_DIR
access parameters
(RECORDS delimited by newline SKIP 1
FIELDS TERMINATED BY ','
LRTRIM
MISSING FIELD VALUES ARE NULL
)
LOCATION (TEST.txt)
)
REJECT LIMIT UNLIMITED);
I know the external table recognizes each field terminated by a comma, but let's say in the text file I have the following
TEST.txt
customer_id, customer_name, customer_number
1,a,10
2,b,11
3,c,12
4,Hello, Inc,13
For the 4 row in the txt file, because there is an additional ',' in the customer_name field, the external table isn't able to properly read the customer name into the table. Is there a way for me to adjust the external table so that it ignores additional ',' or any special characters?
As far as I know, there are 2 ways to do that:
optionally enclose string into e.g. double quotes
change delimiter from comma to something else, e.g. semi-colon
Otherwise, there's no way to leave it "as is" and make Oracle recognize which comma represents what.

Multiple Line - Multiple CLOB per line SQL Loader

I'm finding myself in a predicament.
I am parsing a logfile of multiple entries of SOAP calls. Each soap call can contain payloads of 4000+ characters preventing me to use varchar2. So I must use a CLOB)
I have to load those payloads onto a oracle DB (12g).
I succesfully split the log into single fields and got the payloads and the header of the calls in two single files.
How do I create a CTL file that loads from an infile (that contains data for other fields) and reads CLOB files in pairs?
Ideally:
LOAD DATA
INFILE 'load.ldr'
BADFILE 'load.bad'
APPEND
INTO TABLE ops_payload_tracker
FIELDS TERMINATED BY 'ยง'
TRAILING NULLCOLS
( id,
direction,
http_info,
payload CLOB(),
header CLOB(),
host_name)
but then I don't know, and can't find anywhere on the internet, how to do it for more than one record and how to reference that one record with two CLOBS.
Worth mentioning that it is JBOSS logs, on bash environment.
check size of varchar type in 12c. I thought it was increased to 32K
https://oracle-base.com/articles/12c/extended-data-types-12cR1
see that sample SQL Loader, CLOB, delimited fields
"I already create two separate files for payload and headers. How
should I specify that the two files are there for the same ID?"
see example here:
https://oracle-base.com/articles/10g/load-lob-data-using-sql-loader
roughly:
sample table
1,one,01-JAN-2006,1_clob_header.txt,2_clob_details.txt
2,two,02-JAN-2006,2_clob_heder.txt,2_clob_details.txt
ctl
LOAD DATA
INFILE 'lob_test_data.txt'
INTO TABLE lob_tab
FIELDS TERMINATED BY ','
(number_content CHAR(10),
varchar2_content CHAR(100),
date_content DATE "DD-MON-YYYY" ":date_content",
clob_filename FILLER CHAR(100),
clob_content LOBFILE(clob_filename) TERMINATED BY EOF,
blob_filename FILLER CHAR(100),
blob_content LOBFILE(blob_filename) TERMINATED BY EOF)

Multiple enclosed-by symbols in SQL*Loader

I am loading a CSV file into an Oracle table. One field in some records is enclosed as "abc#xyz.com" and the same field in other records is enclosed as "'abc#xyz.com'". I need to load only abc#xyz.com.
I used OPTIONALLY ENCLOSED BY '"' but it does not help in the second case. Is there a way to specify two symbols in the OPTIONALLY ENCLOSED BY clause? Or what are the other ways of achieving this?
You can apply an SQL operator to trim the leading and trailing single quotes. For example, with a data file containing:
"abc#xyz.com"
"'abc#xyz.com'"
'abc#xyz.com'
And a control file for a dummy table:
LOAD DATA
TRUNCATE INTO TABLE t42
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
EMAIL CHAR(30) "TRIM(BOTH '''' FROM :EMAIL)"
)
This loads the stripped values:
select * from t42;
EMAIL
------------------------------
abc#xyz.com
abc#xyz.com
abc#xyz.com
As you can see, this will load values which are enclosed in single quotes, double quotes, or both - as long as the singles are within the doubles and not the other way around.

LOAD DATA IN ORACLE

Hi am trying to use load data in oracle. if am using
LINES TERMINATED BY '<>'
it is throwing
SQL*Loader-350: Syntax error at line 1.
Expecting "(", found "LINES".
why it is happening .whether there is no LINES teminated by clause in oracle?
I think LINES TERMINATED is not defined in ORACLE; check Stream Record Format from the ORACLE documentation:
A file is in stream record format when the records are not specified
by size; instead SQL*Loader forms records by scanning for the record
terminator. Stream record format is the most flexible format, but
there can be a negative effect on performance. The specification of a
datafile to be interpreted as being in stream record format looks
similar to the following: INFILE datafile_name ["str
terminator_string"]
Example:
load data
infile 'example.dat' "str '|\n'"
into table example
fields terminated by ',' optionally enclosed by '"'
(col1 char(5),
col2 char(7))
example.dat:
hello,world,|
james,bond,|
See http://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_concepts.htm for more.

Delimeter files issues

I do have a flat file with not a fixed structure like
name,phone_num,Address
bob,8888,2nd main,5th floor,avenue road
Here the last column Address has the value 2nd main,5th floor,avenue road but since the same delimeter , is used for seperating columns also i am not getting any clue how to handle the same.
the structure of flat file may change from file to file.
How to handle such kind of flat files while importing using Informatica or SQL * Loader or UTL Files
I will not have any access to flat file just i should read the data from it but i can't edit the data in flat file.
Using SQLLoader
load data
append
into table schema.table
fields terminated by '~'
trailing nullcols
(
line BOUNDFILLER,
name "regexp_substr(:line, '^[^,]+')",
phone_num "regexp_substr(:line, '[^,]+', 1, 2)",
Address "regexp_replace(:line, '^.*?,.*?,')"
)
you need to change your source file to enclose the fields in an escape character eg:
name,phone_num,Address
bob,8888,^2nd main,5th floor,avenue road^
then in sql-loader you'd put:
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '^'
just pick a delimiter that doesn't normally appear in your data.
If you could get the source data enclosed within double quotes ( or any quotes for that matter) you can make use of 'Optional Quotes' option in Informatica while reading from Flat file

Resources