Oracle Sqlldr error with column having crlf - oracle

I am trying to load a '|' delimited file, but it fails because some columns have crlf values.
I converted the text files to xlsx and imported them successfully using SQL Developer.
I noticed that SQL Developer using a Line Terminator option set to "standard: CR LF, CR or LF".
I suspect that I need to set that in my ctl file, but have been unable to find the correct syntax.
Any assistance would be appreciated.
Here is a screenshot from SQL Developer:

As usual, it helps if you post what you have (in this case, control file, table description and sample data). Without it, we have to guess and that doesn't have to reflect reality.
Sample table:
SQL> create table test
2 (id number,
3 description varchar2(50));
Table created.
Control file (contains sample data):
load data
infile *
replace
continueif next preserve(1:1) != "|"
into table test
fields terminated by '|'
trailing nullcols
(
dummy filler,
id,
description
)
begindata
|1|this is some text
with no meaning
at all
|2|some
more text
Loading session:
SQL> $sqlldr scott/tiger#pdb1 control=test11.ctl log=test11.log
SQL*Loader: Release 21.0.0.0.0 - Production on Sat Nov 26 21:51:53 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 1
Commit point reached - logical record count 2
Table TEST:
2 Rows successfully loaded.
Check the log file:
test11.log
for more information about the load.
Result:
SQL> select * from test;
ID DESCRIPTION
---------- --------------------------------------------------
1 this is some text with no meaning at all
2 some more text
SQL>
[EDIT] Using piece of code #p3consulting suggested: no difference (at least, not in my 21XE database):
Control file (modified line #2, the infile one):
load data
infile * "STR X'220D0A'"
replace
continueif next preserve(1:1) != "|"
into table test
fields terminated by '|'
trailing nullcols
(
dummy filler,
id,
description
)
begindata
|1|this is some text
with no meaning
at all
|2|some
more text
Loading session:
SQL> $sqlldr scott/tiger#pdb1 control=test11.ctl log=test11.log
SQL*Loader: Release 21.0.0.0.0 - Production on Sun Nov 27 12:34:04 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
SQL*Loader-283: file processing string "STR X'220D0A'" ignored for INFILE *
Path used: Conventional
Commit point reached - logical record count 1
Commit point reached - logical record count 2
Table TEST:
2 Rows successfully loaded.
Check the log file:
test11.log
for more information about the load.
Result: no difference:
SQL> select * from test;
ID DESCRIPTION
---------- --------------------------------------------------
1 this is some text with no meaning at all
2 some more text
SQL>
[EDIT #2: removed CONTINUEIF]
load data
infile * "STR X'220D0A'"
replace
into table test
<snip>
begindata
<snip>
Loading session:
SQL> $sqlldr scott/tiger#pdb1 control=test11.ctl log=test11.log
SQL*Loader-283: file processing string "STR X'220D0A'" ignored for INFILE *
<snip>
Ah! I should've read the message, Oracle says it all:
file processing string "STR X'220D0A'" ignored for INFILE
So: with a new control file:
load data
infile "c:\temp\test11.txt" "STR X'220D0A'"
replace
into table test
fields terminated by '|'
trailing nullcols
(
dummy filler,
id,
description
)
and data in a separate, test11.txt file:
|1|this is some text
with no meaning
at all
|2|some
more text
Loading session:
<snip>
Commit point reached - logical record count 1
Table TEST:
1 Row successfully loaded.
Check the log file:
test11.log
for more information about the load.
Result:
SQL> select * from test;
ID DESCRIPTION
---------- --------------------------------------------------
1 this is some text
with no meaning
at all
SQL>
That looks A LOT better now!
Though, row#2 is missing. Log file doesn't say anything about it:
SQL> $type test11.log
SQL*Loader: Release 21.0.0.0.0 - Production on Sun Nov 27 15:30:39 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
Control File: test11.ctl
Data File: c:\temp\test11.txt
File processing option string: "STR X'220D0A'"
Bad File: test11.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 250 rows, maximum of 1048576 bytes
Continuation: none specified
Path used: Conventional
Table TEST, loaded from every logical record.
Insert option in effect for this table: REPLACE
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
DUMMY FIRST * | CHARACTER
(FILLER FIELD)
ID NEXT * | CHARACTER
DESCRIPTION NEXT * | CHARACTER
Table TEST:
1 Row successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 129000 bytes(250 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 1
Total logical records rejected: 0
Total logical records discarded: 0
Run began on Sun Nov 27 15:30:39 2022
Run ended on Sun Nov 27 15:30:39 2022
Elapsed time was: 00:00:00.17
CPU time was: 00:00:00.11
SQL>
No bad nor discard file:
SQL> $type test11.bad
The system cannot find the file specified.
SQL> $del test11.dsc
Could Not Find c:\temp\test11.dsc
SQL>
The input file looks like this (when all characters are displayed):
[FINALLY]
p3consulting: 22 is not the hex for | ... it's 7C... but you need to finish the record by |CRLF... your rows end with only CRLF.
Bingo!
Control file:
load data
infile "c:\temp\test11.txt" "STR X'7C0D0A'"
replace
into table test
fields terminated by '|'
trailing nullcols
(
dummy filler,
id,
description
)
Test11.txt:
|1|this is some text
with no meaning
at all|
|2|some
more text|
Loading:
SQL> $sqlldr scott/tiger#pdb1 control=test11.ctl log=test11.log
SQL*Loader: Release 21.0.0.0.0 - Production on Sun Nov 27 17:11:21 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 2
Table TEST:
2 Rows successfully loaded.
Check the log file:
test11.log
for more information about the load.
Result:
SQL> select * From test;
ID DESCRIPTION
---------- --------------------------------------------------
1 this is some text
with no meaning
at all
2 some
more text
SQL>

Try
INFILE 'target.dat' "STR X'220D0A'"
The terminator_string is specified as either 'char_string' or X'hex_string' where:
'char_string' is a string of characters enclosed in single or double quotation marks
X'hex_string' is a byte string in hexadecimal format that you can get with the cast_to_raw function.
So here X'220D0A' is "|CRLF" and this will keep the "CRLF" in the imported column.

Related

Oracle SQL Loader won't load data while INSERT can (date column, ORA-01858)

I have a simple table
CREATE TABLE MYTABLE
(
MYDATE DATE,
ID NUMBER
)
MYDATE is of default format 'dd-MON-yy'
With matching date format insert works without any problem
INSERT INTO mytable values ('01-JAN-01',1)
As well as SQL Loader
LOAD DATA
INFILE "mytable.dat" "str '##\n'"
INTO TABLE mytable TRUNCATE
FIELDS TERMINATED BY '&,#' TRAILING NULLCOLS
(MYDATE ,ID)
.dat file
01-JAN-01&,#1##
Problem comes when date format of inserted date is not default (which I need), then I get ORA-01861: literal does not match format string Thus I use TO_DATE and it works for INSERT
INSERT INTO mytable values (TO_DATE('1901-02-01 00:00:00','YYYY-MM-DD HH24:MI:SS'),2)
But not for SQL Loader for some reason
.dat file
TO_DATE('1901-02-01 00:00:00','YYYY-MM-DD HH24:MI:SS')&,#2##
Log File
SQL*Loader: Release 19.0.0.0.0 - Production on Fri Sep 16 13:32:33 2022
Version 19.11.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Control File: mytable.ctl
Data File: mytable.dat
File processing option string: "str '##
'"
Bad File: mytable.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 250 rows, maximum of 1048576 bytes
Continuation: none specified
Path used: Conventional
Table MYTABLE, loaded from every logical record.
Insert option in effect for this table: TRUNCATE
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
MYDATE FIRST * CHARACTER
Terminator string : '&,#'
ID NEXT * CHARACTER
Terminator string : '&,#'
Record 1: Rejected - Error on table MYTABLE, column MYDATE.
ORA-01858: a non-numeric character was found where a numeric was expected
Table MYTABLE:
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 129000 bytes(250 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 1
Total logical records rejected: 1
Total logical records discarded: 0
Run began on Fri Sep 16 13:32:33 2022
Run ended on Fri Sep 16 13:32:33 2022
Elapsed time was: 00:00:00.05
CPU time was: 00:00:00.02
I am not sure if I am just missing some syntax here or if it is some limitation of SQL Loader.
Don't set "correct" date format in the CSV file; SQL*Loader can't recognize it.
Contents of the file should be e.g.
1901-02-01 00:00:00&,#1##
but you'd then modify control file to
LOAD DATA
INFILE "mytable.dat" "str '##\n'"
INTO TABLE mytable TRUNCATE
FIELDS TERMINATED BY '&,#' TRAILING NULLCOLS
(MYDATE "to_date(:mydate, 'yyyy-mm-dd hh24:mi:ss')", --> this
ID)

SQL Loader to load into BLOB column from single file

I would like to load a CSV file into an Oracle table. The file have a column that can contain a very long string that will exceed the maximum length for VARCHAR2. Because of that, the table I'm loading into have this column specified as BLOB.
create table MY_TABLE(
COL1 VARCHAR2(100),
COL2 VARCHAR2(100),
COL3 BLOB
);
The CSV file to load look like:
COL1,COL2,COL3
1,qwerty,<very long block of text>
2,asdfgh,<very long block of text>
3,zxcvbn,<very long block of text>
...
How can I load it using SQL Loader? All the sites I could find describe how to use BLOB in order to load separate files, ie:
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)
Source: https://oracle-base.com/articles/10g/load-lob-data-using-sql-loader
How can I load into BLOB from my single CSV file? I would expect that below code would work, but it throws a syntax error:
load data
inflie '/path/to/file.csv'
into table MY_TABLE
fields terminated by ','
(
COL1 CHAR(100),
COL2 CHAR(100),
COL3 BLOB
)
In order to load a very long text, you should use CLOB instead of BLOB. The latter is for storing binary objects, such as video files, pictures or sound files.
The way to load depends whether the CLOB content is stored on your CSV file or you are using an external file locator.
CLOB INSIDE CSV FILE
Take this example. I create a csv example file with a very long text:
$ cat testclob.txt
1;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
My control file looks like
load data
infile '/home/ftpcpl/testclob.txt'
into table test_perf.t
append
fields terminated by ';'
(
c1 integer ,
c2 char(10000)
)
Then I load the file
$ sqlldr test_perf/Oracle_1 control=/home/ftpcpl/testclob.ctl log=/home/ftpcpl/testclob.log
SQL*Loader: Release 12.2.0.1.0 - Production on Tue Aug 11 14:23:21 2020
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 1
Table TEST_PERF.T:
1 Row successfully loaded.
Check the log file:
/home/ftpcpl/testclob.log
for more information about the load.
and the log file looks like
Table TEST_PERF.T:
1 Row successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null
.
CLOB AS EXTERNAL FILE LOCATOR
If the CLOB is inside another file, then you should load the file as:
load data
infile *
replace
into table t
fields terminated by ',' optionally enclosed by '"' trailing nullcols
(
id integer external,
fname filler,
c LOBFILE(fname) TERMINATED BY EOF
)
begindata
1,"c:\temp\demo.out"
2,"c:\temp\load_emoji.sql"
SQL> create table t ( id int, c clob );
Table created.
$ sqlldr userid=scott/tigercontrol=c:\temp\c.ctl
SQL*Loader: Release 12.2.0.1.0 - Production on Fri Sep 8 15:49:55 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 1
Commit point reached - logical record count 2
Table T:
2 Rows successfully loaded.
Check the log file:
c.log
for more information about the load.
SQL> select id, length(c) from t;
ID LENGTH(C)
---------- ----------
1 17640
2 1418

ignore space in column value while loading data using sql loader by oracle

I am trying to load data using oracle sql loader and using space as separator of columns but I am facing problem that one of the columns value including space, I need your support to avoid considering this space as column separator.
I tried to use regexp_replace and replace functions
DSTCOUNTRY " REGEXP_REPLACE(:DSTCOUNTRY,'dstcountry=','')",
the column value is: dstcountry="United States"
and the expecting value to be stored in the table is:
United States
The sql loader command is:
load data
infile 'in'
append
into table test_table
fields terminated by " " optionally enclosed by '"'
TRAILING NULLCOLS
DSTCOUNTRY " REPLACE(:DSTCOUNTRY,'dstcountry=','')",
I am using oracle 10G and 12C.
According to what you posted so far, it is optionally enclosed you're looking for. Here's an example.
Test table:
SQL> create table test (id number, dstcountry varchar2(20));
Table created.
Control file (contains sample data as well):
load data
infile *
replace
into table test
fields terminated by " "
optionally enclosed by '"'
trailing nullcols
(
id,
dstcountry)
begindata
123 "Croatia"
125 "United States"
Loading session and result:
SQL> $sqlldr scott/tiger control=test08.ctl log=test08.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon Srp 22 17:59:23 2019
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
Commit point reached - logical record count 2
SQL> select * from test;
ID DSTCOUNTRY
---------- --------------------
123 Croatia
125 United States
SQL>

SQL Loader issue loading decimal negative numbers

I have the following issue using SQL Loader to load a small table, my process populates a field which can be populated for possitive or negative decimal numbers, and the problem is that when the number is possitive, the process rounds with 2 positions, but if it's negative only use 1 position. I need 2 position, and this is the simple code:
UNRECOVERABLE LOAD DATA
TRUNCATE
INTO TABLE [SCHEMA].TABLE1
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
FIELD1 "trim(:FIELD1 )"
)
Example:
Source: 12345,78 Target: 1234,78
Source: -12345,78 Target: -1234,8
Edit1: It just happend with number with 7 or more integer length (X < -1000000), but I can insert this numbers with regular insert instead of SQLLoader.
Edit2: I have noticed that it is not a problem with sql*loader because the .ctl is already wrong. This file is generated with python and SQL with this properties:
set colsep |
set headsep off
set pagesize 0
set trimspool on
set linesize 10000
set termout off
set feedback off
set arraysize 250
But I dont know where it is defined the lenght of each field, and this looks the error.
I'd say that you're not looking correctly. Data is, probably, stored OK, but you don't see it. Here's an example:
SQL> create table test (field1 number);
Table created.
SQL>
Control file:
load data
infile *
replace into table test
fields terminated by '|' trailing nullcols
(
field1
)
begindata
12345,78
-12345,78
987654321
-987654321
987654321,01234
-987654321,01234
111333444,887766
-112333444,887766
Loading session & the result:
SQL> $sqlldr scott/tiger#orcl control=test26.ctl log=test26.log
SQL*Loader: Release 11.2.0.2.0 - Production on Uto Kol 21 08:52:10 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 7
Commit point reached - logical record count 8
SQL> select * from test;
FIELD1
----------
12345,78
-12345,78
987654321
-987654321
987654321
-987654321
111333445
-112333445
8 rows selected.
SQL>
Ooops! Seems to be wrong, eh? But, if you fix the column format ...
SQL> col field1 format 999g999g999g990d000000
SQL> select * from test;
FIELD1
-----------------------
12.345,780000
-12.345,780000
987.654.321,000000
-987.654.321,000000
987.654.321,012340
-987.654.321,012340
111.333.444,887766
-112.333.444,887766
8 rows selected.
SQL>
See? Everything is here.
I guess that, if you used a GUI, you wouldn't have such problems. The former sentence doesn't mean that you should NOT use SQL*Plus - on the contrary; just ... learn how to use it properly :)
[EDIT, after reading the comment]
It is SET NUMFORMAT you might be looking for:
SQL> select -12334.789123 from dual;
-12334.789123
-------------
-12334,789
SQL> set numformat 999g999g990d000000
SQL> select -12334.789123 from dual;
-12334.789123
-------------------
-12.334,789123
SQL>

SQL LOAD DATA INFILE but keep one field static

I am running the following to load data into a table
OPTIONS (Skip=1)
LOAD DATA
INFILE 'D:\EPM\import\test.txt'
APPEND
INTO TABLE HYP.HS_MEMBER_D
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(
DIMENSION,
PARENT,
CHILD,
ALIAS,
ATTRB01
)
This is working fine but I want to keep the ATTRB01 field as a static value, I want to load "Alloc" for all records, is there a way in this script to load a static value even though I am loading from the file for the other fields?
You'd load a constant, such as
OPTIONS (Skip=1)
LOAD DATA
INFILE 'D:\EPM\import\test.txt'
APPEND
INTO TABLE HYP.HS_MEMBER_D
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(
DIMENSION constant Account,
PARENT,
CHILD,
ALIAS,
ATTRB01 constant 'Alloc' --> this
)
Here's an example: test table:
SQL> desc test
Name Null? Type
----------------------------------------- -------- -------------
ID NUMBER
ATTRB01 VARCHAR2(20)
Control file:
load data
infile *
replace
into table test
fields terminated by ","
trailing nullcols
(
id,
attrb01 constant 'Alloc'
)
begindata
1,xxx
2,yyy
3,zzz
Loading session & the result:
SQL> $sqlldr scott/tiger control=test01.ctl log=test01.log
SQL*Loader: Release 11.2.0.2.0 - Production on Sri Kol 15 21:08:59 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
Commit point reached - logical record count 3
SQL> select * From test;
ID ATTRB01
---------- --------------------
1 Alloc
2 Alloc
3 Alloc
try by using set at end
OPTIONS (Skip=1)
LOAD DATA
INFILE 'D:\EPM\import\test.txt'
APPEND
INTO TABLE HYP.HS_MEMBER_D
FIELDS TERMINATED BY "|"
TRAILING NULLCOLS
(
DIMENSION constant Account,
PARENT,
CHILD,
ALIAS,
ATTRB01
)
set ATTRB01='default_value'

Resources