SQL LOAD DATA INFILE but keep one field static - oracle

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'

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)

sqlloader skips characters during data load into table

using the control file below to load data
LOAD DATA
INFILE '/c/Transaction.txt'
INTO TABLE tab1 APPEND WHEN (1:1) = 'D'
(RUN_ID "RUN_ID_SEQ.NEXTVAL"
,RUN_DATE_TIME "SYSDATE"
)
INTO TABLE tab2 TRUNCATE WHEN(1:1) <> 'D'
FIELDS TERMINATED BY '|' TRAILING NULLCOLS
(
DEALER_NUMBER
,TRAN_CODE
,TRAN_AMOUNT "TO_NUMBER(:PL818_TRAN_AMOUNT,'999999.99')"
,TRAN_DATE "TO_DATE(:PL818_TRAN_DATE,'DD-MM-YYYY')"
)
This is the data set
DEALER_ID|TRAN_TYPE_CODE|TRAN_AMOUNT|TRAN_DATE
203113|34|1000.50|12-07-2022
No errors during load. Data loads correctly into the first table but first two characters are skipped when loading data into second table, table data looks like this. What could be causing this?
3113 34 1000.5 12-JUL-22
Skips "20"
Sample tables:
SQL> desc tab1
Name Null? Type
----------------------------------------- -------- ----------------------------
RUN_ID NUMBER
RUN_DATE_TIME DATE
SQL> desc tab2
Name Null? Type
----------------------------------------- -------- ----------------------------
DEALER_NUMBER NUMBER
TRAN_CODE NUMBER
TRAN_AMOUNT NUMBER
TRAN_DATE DATE
SQL>
Control file; note position(1) when loading into tab2. You must use it when loading data into different tables, using the same control file:
LOAD DATA
INFILE *
INTO TABLE tab1 APPEND WHEN (1:1) = 'D'
(RUN_ID "RUN_ID_SEQ.NEXTVAL"
,RUN_DATE_TIME "SYSDATE"
)
INTO TABLE tab2 TRUNCATE WHEN(1:1) <> 'D'
FIELDS TERMINATED BY '|' TRAILING NULLCOLS
(
DEALER_NUMBER position(1) --> here
,TRAN_CODE
,TRAN_AMOUNT "TO_NUMBER(:TRAN_AMOUNT,'999999.99')"
,TRAN_DATE "TO_DATE(:TRAN_DATE,'DD-MM-YYYY')"
)
BEGINDATA
203113|34|1000.50|12-07-2022
Loading session and the result:
SQL> $sqlldr scott/tiger#orcl control=test42.ctl log=test42.log
SQL*Loader: Release 18.0.0.0.0 - Production on Sri Srp 13 08:28:19 2022
Version 18.5.0.0.0
Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
Path used: Conventional
Commit point reached - logical record count 1
Table TAB1:
0 Rows successfully loaded.
Table TAB2:
1 Row successfully loaded.
Check the log file:
test42.log
for more information about the load.
SQL> select * from tab2;
DEALER_NUMBER TRAN_CODE TRAN_AMOUNT TRAN_DATE
------------- ---------- ----------- ----------
203113 34 1000,5 12-07-2022
--
here's your missing "20"
SQL>

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;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
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>

Load data from CSV file (data seperated by pipe "|") into a table using SQL loader when the data present in double quotes

I am loading CSV file data into table called EMPLOYEE using SQL*Loader.
My CSV file data is separated by pipe (|):
EMPID|EMPNAME_ADDRESS|SALARY|GRADE
123|Rams Hyd|1000|A1
124|Sand MUM|2,000|A2
125|"PRASANNA qwer trasf\"501 advv vvd, qee ggg\trfe \411005 THE|3,00,000|A3
and my control file is:
LOAD DATA
Insert INTO TABLE EMPLOYEE
Fields terminated by "|" Optionally enclosed by '"' TRAILING NULLCOLS
(
EMPID,
EMPNAME,
SALARY,
GRADE
)
When I load the data using above control file, the first two record are loading fine and for the third record i am getting error like as mentioned below.
no terminator found after TERMINATED and ENCLOSED field
Please suggest changes to be done to load the data properly.
Here's a way to load such data.
First, a target table (I hope it makes sense; you should have provided it):
SQL> create table employee
2 (empid number,
3 empname varchar2(200),
4 salary number,
5 grade varchar2(10)
6 );
Table created.
SQL>
Control file: note the SKIP option (which skips the header line), as well as REPLACE function call for the SALARY column (to remove superfluous commas which are formatting stuff; add them later, in the presentation layer).
options (skip = 1)
load data
infile *
replace
into table employee
fields terminated by "|" TRAILING NULLCOLS
(
empid,
empname,
salary "replace(:salary, ',', null)",
grade)
begindata
EMPID|EMPNAME_ADDRESS|SALARY|GRADE
123|Rams Hyd|1000|A1
124|Sand MUM|2,000|A2
125|"PRASANNA qwer trasf\"501 advv vvd, qee ggg\trfe \411005 THE|3,00,000|A3
Loading session:
SQL> $sqlldr scott/tiger control=test06.ctl log=test06.log
SQL*Loader: Release 11.2.0.2.0 - Production on Uto Tra 9 19:37:46 2019
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 employee;
EMPID EMPNAME SALARY GRADE
---------- ---------------------------------------- ---------- ----------
123 Rams Hyd 1000 A1
124 Sand MUM 2000 A2
125 "PRASANNA qwer trasf\"501 advv vvd, qee 300000 A3
ggg\trfe \411005 THE
SQL>

Resources