load decimal into oracle table with sql loader - oracle

I have this table in oracle :
CREATE TABLE mytable
(
TSTAMP Date,
prmc1 VARCHAR2(30),
prmc2 VARCHAR2(30),
prmc3 VARCHAR2(30),
prmc4 VARCHAR2(30),
prmc5 NUMBER,
prmc5 NUMBER,
prmc6 NUMBER
)
the control file is below :
load data
append
into table mytable
fields terminated by ',' TRAILING NULLCOLS
( tstamp DATE "YYYY-MM-DD HH24:MI" TERMINATED BY ",",
prmc1 ":prmc1",
prmc2 ":prmc2",
prmc3 ":prmc3",
prmc4 ":prmc4",
prmc5 INTEGER ":prmc5",
prmc6 INTEGER ":prmc6"
)
the value of the column prmc5 in the csv file is -106.436
how do i load this into the table?

You just need to specify it as DECIMAL EXTERNAL
I am also removing specifying the format as the column itself.
load data
append
into table mytable
fields terminated by ',' TRAILING NULLCOLS
( tstamp DATE "YYYY-MM-DD HH24:MI" TERMINATED BY ",",
prmc1 ,
prmc2 ,
prmc3 ,
prmc4 ,
prmc5 DECIMAL EXTERNAL,
prmc6 DECIMAL EXTERNAL
)
More details with some Example here

Related

Oracle SQL loader control file creation for date and time

I am using below CTL file to load data into table
Load data
Append
Into table abc
Fields terminated by ',' optionally enclosed by '"'
Trailing nullcols
(
R_date date 'mm/dd/yyyy hh:mm:ss'
)
Csv file value is as
R_date
09/12/2023 12:30:34
08/11/2023 22;30:45
In table abc r_date column datatype is date.
Ora-01840 input value not long enough for date format.
Noting we have written in above file
I think you want:
R_date date "mm/dd/yyyy hh24:mi:ss"

External Tables - Replace comma with dot in numbers

How can I replace a comma with a dot directly from the external table?
I have a CSV with that format:
aaa;12345.67;bbbbbb
ccc;23132;eeeee
Sometimes someone puts a line like that:
ddd;1111,22;fff
CREATE TABLE MYTAB_EXT
(
"TX1" VARCHAR2(20 BYTE),
"VAL1" NUMBER(13,3),
"TX2" VARCHAR2(20)
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER DEFAULT DIRECTORY "EXT_TABLES_FOO" ACCESS
PARAMETERS (
records delimited BY newline
SKIP 1
fields terminated BY ';' LRTRIM
missing field VALUES are NULL (
TX1 ,
VAL1 ,
TX2)
) LOCATION ( 'MYTAB.csv' )
)
REJECT LIMIT UNLIMITED;
Thanks

sql loader : Load string greater than 4000 characters using sql loader

I need to load a CSV file into table using sql loader but the lenth of a column is exceeding the Max length of varchar2 data type.
Create table statement :
CREATE TABLE TEST_PIPE_SEP (FILE_NM VARCHAR2(3000), KEY_COL VARCHAr2(4000), DESCR VARCHAR2(4000), RUN_DATE DATE );
CTL file :
load data
into table test_pipe_sep
append
fields terminated by ','
TRAILING NULLCOLS
(
FILE_NM char(4000) "trim(:FILE_NM)",
KEY_COL char(4000) "trim(:KEY_COL)",
DESCR "trim(:DESCR)",
RUN_DATE "to_date(sysdate, 'dd-mon-yyyy hh24:mi:ss')"
)
CSV sample record :
sample_file_name.csv,"B"|"STRESS_TESTING_SCENARIO_ID"|"TRANCHE_COLLATERAL_TYPE"|"TRANCHE_GUARANTEE_TYPE"|"BS_TYPE"|"CONTRACT_REFERENCE"|"CONTRACT_TYPE"|,Not Present in file2
I just not paste the full text here as it will become lengthy but you can append the length of middle column in CSV or KEY_COL field value to more than 4000 for testing.
SQLLDR :
sqlldr userid=$SQL_CREDENTIALS control=new_test_3.ctl data=data/$filename log=logs/$filename.log bad=logs/$filename.bad skip=1
Please suggest if there is any way where we can load a string of length more than 4000 using SQL LOADER or is there any workaround for this kind of problem.
I am on :
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
I did it ! :)
Change the column data type to CLOB as below :
CREATE TABLE TEST_PIPE_SEP (FILE_NM VARCHAR2(3000), KEY_COL CLOB, DESCR VARCHAR2(4000), RUN_DATE DATE );
Then the CTL I used to load data into CLOB column is as below :
load data
into table test_pipe_sep
append
fields terminated by ','
TRAILING NULLCOLS
(
FILE_NM char(4000) "trim(:FILE_NM)",
KEY_COL CHAR(30000) optionally ENCLOSED BY '<' AND '>',
DESCR "trim(:DESCR)",
RUN_DATE "to_date(sysdate, 'dd-mon-yyyy hh24:mi:ss')"
)

Identifier is too long while loading from SQL*Loader

I have a table structure like this
CREATE TABLE acn_scr_upload_header
(
FILE_RECORD_DESCRIPTOR varchar2(5) NOT NULL,
schedule_no Number(10) NOT NULL,
upld_time_stamp Date NOT NULL,
seq_no number NOT NULL,
filename varchar2(100) ,
schedule_date_time Date
);
When I try to load my file via SQL*Loader I'm getting an error on this value in the column filename: Stock_Count_Request_01122014010101.csv. The error is:
Error on table ACN_SCR_UPLOAD_HEADER, column FILENAME.
ORA-00972: identifier is too long".
If I try to insert the same value into the table using an INSERT statement it works fine.
My data file Stock_Count_Request_01122014010101.csv looks like
FHEAD,1,12345,20141103
FDETL,7,100,W,20141231,SC100,B,N,1,5
FTAIL,8,6
and control file
LOAD DATA
INFILE '$IN_DIR/$FILENAME'
APPEND
INTO TABLE ACN_SCR_UPLOAD_HEADER
WHEN FILE_RECORD_DESCRIPTOR = 'FHEAD'
FIELDS TERMINATED BY ","
TRAILING NULLCOLS
(
FILE_RECORD_DESCRIPTOR position(1),
LINE_NO FILLER,
schedule_no ,
schedule_date_time,
upld_time_stamp sysdate,
seq_no "TJX_STOCK_COUNT_REQ_UPLD_SEQ.NEXTVAL",
FILENAME constant ""
)

Oracle SQLLOADER - How to Load Data in format of dd-mon-rr

I have text comma separated file in format below.
"RAZY","","","","","","","","N","Y","27-JUL-14","1","98727076437","27-JUL-14"
"TEST","","","","","","","","N","Y","27-JUN-14","1","98727076437","27-JUN-79"
I am trying to load this using a SQL loader controlfile.
OPTIONS (SKIP=0)
LOAD DATA
INFILE '/home/test.txt'
BADFILE '/home/test.bad'
DISCARDFILE '/home/test.dis'
APPEND
INTO TABLE "TEST"
fields terminated by ","
optionally enclosed by '"'
TRAILING NULLCOLS
(
NAME ,
TITLE ,
INITIAL ,
SURNAME ,
STREET ,
TOWN ,
COUNTY ,
POSTCODE ,
TELEPHONE ,
FLAG ,
Update_DATE DATE "TO_DATE(:Update_DATE,'DD-MON-RR')",
Update_STATUS ,
VISIT_REFERENCE ,
LOADED_DATE DATE "TO_DATE(:LOADED_DATE,'DD-MON-RR')"
)
But returned an error "ORA-01821: date format not recognized"
Thanks
Try this.
Update_DATE DATE "DD-MON-RR",
LOADED_DATE DATE "DD-MON-RR"

Resources