SQL*Loader reading a file with missing columns - oracle

I need to create a SQL*Loader control file that can read source files with missing columns. For example, file a:
a;b;c
And file b:
a;b
My control file looks like this:
load data
APPEND
into table table_of_parameter
fields terminated by ";" optionally enclosed by '"'
TRAILING NULLCOLS
(
parameters1,
parameters2,
parameters3
)
And I want this to be the result of loading both files:
select * from table_of_parameter
parameters1 parameters2 parameters3
a b c
a b null (or something else)
Is there a way to do this in a control file?

i solved this issue..
the problem was that the last paramether is "not Null"
so, if i put a different amount of value, it populare previous parameters that have "default value null" and can't populate this paramether.
Solved moved it before this paramether

Related

Can Oracle SQL*Loader check for extra delimiters?

From tests done, it seems that loading does not fail if the file contains extra delimiters.
Let say I have a control file with 3 columns a,b,c as follows
LOAD DATA
TRUNCATE INTO TABLE test
FIELDS TERMINATED BY "|" trailing nullcols
(
a,
b,
c
)
But the file contains extra delimiters in some of the rows. As example:
1|2|3
4|5|6
7|8|9|10
11|12|13
In the above example, row 3 contains an extra delimiter but loading is successful and the last value (10) is not loaded.
Can you specify some option in the control file to treat row 3 as bad or discard?
Validations of the input file can be done prior to loading but wanted to check if the loader itself supports such feature.

sqlldr : Could I use the comma delimiter field terminate and optional enclose simultaneously?

I have a CSV file that contains a list of famous singers in the world. I want to import this file to Oracle DB using SQLLDR.
Contains of singers.csv is:
number,name,follower
1,Prince,100
2,Ludacris,100
3,Bruno Mars,100
4,Madonna,100
5,Miley,Cyrus,100
6,Britney,Spears,100
control.ctl
OPTIONS (SKIP=0, errors=12000)
LOAD DATA
APPEND INTO TABLE singers_tb
FIELDS TERMINATED BY ","
optionally enclosed by '"'
TRAILING NULLCOLS
(number ":number", name "TRIM (:name)",follower ":follower")
singers_tb
create singers_tb (
number varchar2(3),
name varchar2(255),
follower number
)
error message
Record 5: Rejected - Error on table singers_tb, column FOLLOWER.
ORA-01722: invalid number
Record 6: Rejected - Error on table singers_tb, column FOLLOWER.
ORA-01722: invalid number
I know the cause of the error is the comma (,) on Britney,Spears and Miley,Cyrus.
How to solve these problems if I still want to use FIELDS TERMINATED BY "," ?
Thanks you very much for your suggestion.
Your control file already has: optionally enclosed by '"'.
Make sure the data provider indeed provides that any field containing your delimiter arrive surrounded by double quotes.

insert timestanp of INFILE into a column from SQLLOADER

I have a requirement as below,
Am calling sqlldr script via shell for the CSV files present in a folder, File name also has Timestamp attached with it.
I need to insert that timestamp into a column of table. Kindly suggest me how i can achieve this.
eg:
table:
t1(c1 varchar,c2 varchar,c3 timestamp);
control file :
load data
infile 'file.csv'
append
into table t1
fields terminated by "|" TRAILING NULLCOLS
( c1, c2)
csv_file : cat file_csv_101010112233.csv
1111|1
2222|2
OUTPUT :
select * from t1;
c1 c2 c3
1111 1 101010112233
2222 2 101010112233
Note : I dont want the sys timestamp
I think you will need a shell script wrapper around calling sqlldr. First alter the control file so the timestamp column has a placeholder like:
...
C3 CONSTANT REPLACE_ME,
...
And save it as a template.
The wrapper should back up the original csv file, get the timestamp from the filename, then use something like sed to replace the "REPLACE_ME" text in the template control file with saved timestamp data and save it to a working copy, then call Sqlldr using the working copy.
I was thinking of other ways to do this and came up with one. May not be feasible for your environment but something to keep in mind anyway.
If you can get the data file name into a column (maybe a load_log table for example that would get populated at the start of the load), you could assign it like this by calling a function that returns the name:
C3 "package.function"
More info: SQL*Loader Field List Reference

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

SQLLDR -- selective loading from pipe delimited txt

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)

Resources