Number/s rejected as invalid when Direct=True - oracle

My ctl file:
OPTIONS (ERRORS=50000000, SKIP=1, DIRECT=true )
LOAD DATA
INFILE '\\*****path******\TAT_OUTPUTS\AMINET\1\1.csv'
BADFILE'\\********path***********\1_BAD.csv'
DISCARDFILE'\\***********path************\1_DSC.csv'
TRUNCATE INTO TABLE MY_TABLE
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(A , B, ....
My input csv file looks like
A|B
test|0
I am getting the following error:
Record 1: Rejected - Error on table MY_TABLE, column B.
ORA-01722: invalid number
If I remove the DIRECT=true flag from the ctl file options. I am not getting the above error. I need DIRECT flag and so can't remove it.
How can I solve this?

Related

Can we change Case of input data in SQL LOADER ctl file?

I am trying to insert data from csv to a table using sql loader.
My csv has data in small Caps .But I want the data in the table to be in Large cap for some columns For some Columns it should be InitCap.
INFILE 'abc.csv'
INSERT INTO TABLE T_DETAILS
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(
INITCAP(f_name),
UPPER(f_code)```
But i am getting error like
> **SQL*Loader-350: Syntax error at line 16. Expecting "," or ")", found "(".
> INITCAP(f_name),**
> ^
You can, but not like that. Should've been
load data
infile 'abc.csv'
insert
into table t_details
fields terminated by ',' optionally enclosed by '"' trailing nullcols
(f_name "initcap(:f_name)",
f_code "upper(:f_code)"
)

Oracle Sql Loader "ORA-01722: invalid number" when loading CSV file with Windows line endings

I am using Oracle Sql Loader Utility from Linux shell to load csv data into Oracle DB.
But I have noticed that if source csv files lines endings are '\r\n' (Windows format), sqlldr fails to load data for last column.
For example, if last column is of FLOAT type (defined in ctl file as 'FLOAT EXTERNAL'), sqlldr fails with 'ORA-01722: invalid number':
Sqlldr ctl file:
OPTIONS(silent=(HEADER))
load data
replace
into table fp_basic_bd
fields terminated by "|" optionally enclosed by '"'
TRAILING NULLCOLS
(
FS_PERM_SEC_ID CHAR(20),
"DATE" DATE "YYYY-MM-DD",
ADJDATE DATE "YYYY-MM-DD",
CURRENCY CHAR(3),
P_PRICE FLOAT EXTERNAL,
P_PRICE_OPEN FLOAT EXTERNAL,
P_PRICE_HIGH FLOAT EXTERNAL,
P_PRICE_LOW FLOAT EXTERNAL,
P_VOLUME FLOAT EXTERNAL
)
sqlldr execution command:
sqlldr -userid XXX -data ./test.data -log ./test.log -bad ./test.errors -control test.ctl -errors 3 -skip_unusable_indexes -skip_index_maintenance
sqlldr error log:
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
FS_PERM_SEC_ID FIRST 20 | O(") CHARACTER
"DATE" NEXT * | O(") DATE YYYY-MM-DD
ADJDATE NEXT * | O(") DATE YYYY-MM-DD
CURRENCY NEXT 3 | O(") CHARACTER
P_PRICE NEXT * | O(") CHARACTER
P_PRICE_OPEN NEXT * | O(") CHARACTER
P_PRICE_HIGH NEXT * | O(") CHARACTER
P_PRICE_LOW NEXT * | O(") CHARACTER
P_VOLUME NEXT * | O(") CHARACTER
value used for ROWS parameter changed from 300000 to 65534
Record 1: Rejected - Error on table FP_BASIC_BD, column P_VOLUME.
ORA-01722: invalid number
Record 2: Rejected - Error on table FP_BASIC_BD, column P_VOLUME.
ORA-01722: invalid number
When I replaced Windows line endings to Unix ones, all errors gone and all data loaded correctly.
My question is: how could I specify line terminator char in sqlldr config file but still keep the source file name in shell command?
I've seen some examples of how to do that with stream record format http://docs.oracle.com/cd/E11882_01/server.112/e16536/ldr_control_file.htm#SUTIL1087,
but these examples are not applicable in my case as I need to keep name of data file in shell command, and not inside ctl file.
I recently encountered the same issue while loading data into my table via csv file.
My file looked like this :
LOAD DATA
infile '/ipoapplication/utl_file/LBR_HE_Mar16.csv'
REPLACE
INTO TABLE LOAN_BALANCE_MASTER_INT
fields terminated by ',' optionally enclosed by '"'
(
ACCOUNT_NO,
CUSTOMER_NAME,
LIMIT,
REGION,
TERM_AGREEMENT INTEGER EXTERNAL
)
And as you mentioned , i kept getting the same error 'invalid number'
Turns out this usually occurs
-when your column datatype is Number but data you're getting from your csv file is in string,so oracle loader fails to perform a conversion of string to number.
- when your field in csv file is terminated by some delimiters ,say space,tabs etc.
This is how i altered my ctl file :
LOAD DATA
infile '/ipoapplication/utl_file/LBR_HE_Mar16.csv'
REPLACE
INTO TABLE LOAN_BALANCE_MASTER_INT
fields terminated by ',' optionally enclosed by '"'
(
ACCOUNT_NO,
CUSTOMER_NAME,
LIMIT,
REGION,
TERM_AGREEMENT INTEGER Terminated by Whitespace
)
Try using stream record format and specifying the terminator string. From the docs
On UNIX-based platforms, if no terminator_string is specified, SQL*Loader defaults to the line feed character, \n.
The terminator string should allow you to specify a combination of characters.

How to use decode in sql-loader?

I use sqlldr to import CSV files and I have some problem with date multiple formats.
Dates inside the CSV file are DD/MM/YYYY and if there is no date it is a single dot
CSV file
DATE_COLUMN;OTHER_COLUMN
01/01/2013;other column content 1
.;other column content 2
My .ctl file for sqlldr
LOAD DATA
INFILE '/path/to/my/file.csv'
REPLACE INTO TABLE table_to_fill
FIELDS TERMINATED BY ';'
(
COLUMNDATE "decode(:COLUMNDATE ,NULL,'.', to_date(:COLUMNDATE ,'DD/MM/YYYY'))",
OTHER_COLUMN
)
The import is working when I use :
decode(:COLUMNDATE ,NULL,'.'))
or
to_date(:COLUMNDATE ,'DD/MM/YYYY')
But not when I try to combine both...
Here is the error log :
Record 1: Rejected - Error on table table_to_fill, column COLUMNDATE.
ORA-01858: a non-numeric character was found where a numeric was expected
How can I combine these, please ?
I thought that the last parameter of the "decode" function was for the default value of the column, am I wrong ?
SQL Loader's "regular" syntax should be enough here. Try this:
LOAD DATA
INFILE '/path/to/my/file.csv'
REPLACE INTO TABLE table_to_fill
FIELDS TERMINATED BY ';'
(
COLUMNDATE DATE(7) "DD/MM/YYYY" NULLIF COLUMNDATE = "."
OTHER_COLUMN
)

Loading text file in oracle from unix system

I am having text file contaning field in below manner.
"64252368","7489040","305762",
"64285217","12132108","787341",
I am using a below control file.
OPTIONS (SKIP=1)
LOAD DATA
TRUNCATE INTO TABLE test_table
FIELDS TERMINATED BY '",'
(
LEARNEVENT_ID,
ORGANIZATION,
COURSE_ID
)
But, I am getting the error:
Record 1: Rejected - Error on table test_table, column LEARNEVENT_ID
ORA-01722: invalid number
Kindly help me on it.
You need to change your ctl file to include OPTIONALLY ENCLOSED BY option.
OPTIONS (SKIP=1)
LOAD DATA
TRUNCATE INTO TABLE test_table
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
(
LEARNEVENT_ID,
ORGANIZATION,
COURSE_ID
)
I'd recommend reading up on SQL*Loader.
The problem lays with the encapsulation of the numbers with the quotes " " and your fields terminated by '",' simply does not strip the quotes.
Try this
OPTIONS(SKIP=1)
LOAD DATA
TRUNCATE INTO TABLE test_table
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(
LEARNEVENT_ID "replace ( :LEARNEVENT_ID ,'"', '')",
ORGINAZATION "replace ( :ORGINAZATION ,'"', '')",
COURSE_ID "replace ( :COURSE_ID ,'"', '')"
)

Oracle SQLLDR Discard rows using WHEN clause not working

I am trying to load a text file, only those rows where 3rd column 'c_nbr' Doesn't END with 'ABCD'. Since WHEN clause is really primitive I could not use, trim/substring with it.
My second choice was to put the last 4 chars of c_nbr field to a column called 'MSGCOL' and use that column in my WHEN clause, like " WHEN MSGCOL <> 'ABCD' ".
The MSGCOL is getting value "ABCD" where column 'c_nbr' ends with "ABCD", but the WHEN clause is not DISCARDing them.
Why it's not working? How can I achieve my goal? Can I run SQL Query from sqlldr control file itself? Like "Delete from tbl_load where c_nbr like '%ABCD';" at the end of loading commands?
SQLLDR Control File:-
OPTIONS (ERRORS=9999)
LOAD DATA
INFILE '052140.csv'
BADFILE '052140.BAD'
DISCARDFILE '052140.DIS'
INFILE '055913.csv'
BADFILE '055913.BAD'
DISCARDFILE '055913.DIS'
APPEND INTO TABLE tbl_load
WHEN MSGCOL <> 'ABCD'
FIELDS TERMINATED BY ',' optionally enclosed by '"' trailing nullcols
(
id "TRIM(UPPER(:ID))",
pid,
c_nbr "TRIM(:c_nbr)",
a_nbr "SUBSTR(TRIM(:a_nbr), 1, 25)",
P_REASON2 FILLER,
MSGCOL EXPRESSION "substr(trim(:c_nbr), length(trim(:c_nbr))-3, 4)"
)

Resources