SQLLDR : merger year,mon and day - oracle
I have csv file that contains shown below :
year,mon,day
2014,12,01
2013,10,30
and abc's table
create table abc (
year varchar2(4),
mon varchar2(2),
day varchar2(2),
date1 date
)
how to tell loader.ctl to merger year,mon,day become date?
like that ?
OPTIONS (SKIP=11, errors=12000)
LOAD DATA
APPEND INTO TABLE abc (
year "trim (:year)",
mon "trim (:mon)",
day "trim (:day)",
date1 "to_date (year||mon||day,'yyyymmdd')"
)
Since your fields are comma separated, you should include fields terminated by "," in your control file.
date1 is not present in the data file, but is computed. So use EXPRESSION parameter to specify that.
in to_date function, use colons to reference the previous fields.
So, your control file should look like this,
OPTIONS (SKIP=11, errors=12000)
LOAD DATA
APPEND INTO TABLE abc
fields terminated by ","
(
year "trim (:year)",
mon "trim (:mon)",
day "trim (:day)",
date1 EXPRESSION "to_date (:year||:mon||:day,'yyyymmdd')"
)
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"
sql * loader file not axtracting (DATE DATATYPE)
LOAD DATA INFILE "C:\\Users\\lenovo T480\\Desktop\\all_2012.csv" DISCARDFILE "C:\\Users\\lenovo T480\\Desktop\\BANKING_DATA_DISCARDED.txt" TRUNCATE INTO TABLE BANKDTLS FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '""' (year,BACH,ACODE,XNUM,BANK,location,AREA,HEAD_NAME, CODETX,BALANCE,COL_PIVOT,CONSOLD,DEPTNO,DEBIT,STATUS, SUB_ADDR,PROVINCE,CONTRY,COLNO1,COLNO2,CREDIT,ADD_STATUS, DATE1, DATE2, INTEREST,TAX,GENDER,STATES,STATE_CODE,type,TYPE_CODE,LOAN_CODE,LOAN_TYPE) 3 ROWS SAMPLE OF CSV FILE 2012,19048,152,286690,compass_bank,3805_a1a_south,saint_augustine,st_johns,fl,32080,brcenm,consold,11,33_317,0,los_angeles_long_beach_glendale_ca,saint_augustine_2,united_states,109,300,27260,1,9_17_97,6_30_86,29_826612,81_272145,m,florida,12,mult,1391237,4,commercial_lending,banco_bilbao_vizcaya_argentaria_s_a,bilbao,al,697633,0_5,15_south_20th_street,birmingham,al_2,35233,65_982_103,sm,call,state,state_agency,state_2,13,united_states_2,0_6,48_097_626,48_313_018,10256,escrow,5,atlanta,6,atlanta_2,dif,cb,insbrdd,insbrts,5_2,southwest_district,fed,1073,alabama,1_2 2012,19048,660,257606,Compass Bank,3809 East 42nd Street,Odessa,Ector,TX,79762,M,,11,28063,FALSE,Chicago-Naperville-Arlington Heights IL,Odessa,United States,135,372,36220,TRUE,3/13/2008,1/4/1993,31.891448,-102.343769,M,Texas,48,MULT,1391237,4,COMMERCIAL LENDING,BANCO BILBAO VIZCAYA ARGENTARIA S.A.,BILBAO,AL,697633,FALSE,15 South 20th Street,Birmingham,AL,35233,65982103,SM,CALL,STATE,State Agency,STATE,13,United States,FALSE,48097626,48313018,10256,,5,Atlanta,6,Atlanta,DIF,CB,,,5,Southwest District,FED,1073,ALABAMA,TRUE 2012,19048,620,196395,Compass Bank,3810 Hwy 365,Port Arthur,Jefferson,TX,77642,C,956,23,0,FALSE,,Port Arthur,United States,245,0,13140,TRUE,3/13/2008,3/8/1993,29.915512,-93.877536,M,Texas,48,MULT,1391237,4,COMMERCIAL LENDING,BANCO BILBAO VIZCAYA ARGENTARIA S.A.,BILBAO,AL,697633,FALSE,15 South 20th Street,Birmingham,AL,35233,65982103,SM,CALL,STATE,State Agency,STATE,13,United States,FALSE,48097626,48313018,10256,,5,Atlanta,6,Atlanta,DIF,CB,,,5,Southwest District,FED,1073,ALABAMA,TRUE --TABLE Create table BANKDTLS ( year number(4),BACH number(25),ACODE number(30),XNUM number(26), BANK varchar2(70),location varchar2(70),AREA varchar2(50),HEAD_NAME varchar2(40), CODETX varchar(30),BALANCE varchar(20),COL_PIVOT varchar(25),CONSOLD varchar(20), DEPTNO varchar(30),DEBIT varchar(30),STATUS varchar(10), SUB_ADDR varchar2(50), PROVINCE varchar2(50),CONTRY varchar2(50), COLNO1 varchar(40), COLNO2 varchar(40), CREDIT varchar(38),ADD_STATUS varchar2(46), DATE1 DATE, DATE2 DATE, INTEREST varchar2(30), TAX varchar(25), GENDER varchar(30), STATES varchar2(30), STATE_CODE varchar(30),type varchar2(36),TYPE_CODE varchar(30), LOAN_CODE varchar(35), LOAN_TYPE varchar2(50) ); --columns(date1,date2) --TABLE AND COLUMNS CREATED IN ORACLE WITH DATE DATATYPE --DATE FORMAT IN FLAT FILE (9/31/2012) --/*value used for ROWS parameter changed from 250 to 123 Record 1: Rejected - Error on table BANKDTLS, column DATE1. ORA-01843: not a valid month Record 2: Rejected - Error on table BANKDTLS, column DATE1. ORA-01843: not a valid month Record 3: Rejected - Error on table BANKDTLS, column DATE1. ORA-01843: not a valid month*/ HOW TO INSERT STRING DATA INTO DATE (DATATYPE) COLUMN USING SQLLOADER AND ALREADY TABLE CREATED WITH DATE(DATATYPE)*
If you don't specify the source field datatype, SQLLoader reads everything as CHAR(255). It doesn't know how to stick a CHAR value into a DATE column unless the format just happens to match the database's (or session's) NLS_DATE_FORMAT parameter. Programmers should never rely on that. Instead, they should always specify the date format their data is in. For SQLLoader control files, you can do that in the field definition. For example: . . . (year,BACH,ACODE,XNUM,BANK,location,AREA,HEAD_NAME, CODETX,BALANCE,COL_PIVOT,CONSOLD,DEPTNO,DEBIT,STATUS, SUB_ADDR,PROVINCE,CONTRY,COLNO1,COLNO2,CREDIT,ADD_STATUS, DATE1 DATE "YYYYMMHH24MISS", DATE2 DATE "YYYYMMHH24MISS", INTEREST,TAX,GENDER,STATES,STATE_CODE,type,TYPE_CODE,LOAN_CODE,LOAN_TYPE) Change that to whatever format your date strings are in, and it should parse it correctly and then will be loading a date into a date.
In the control file you need to also specify the types and format for the date: ... DATE1 DATE "MM/DD/YYYY" NULLIF (DATE1=BLANKS), DATE2 DATE "MM/DD/YYYY" NULLIF (DATE2=BLANKS), ...
DateTime Format in Oracle SQL Loader [duplicate]
The data from the infile is in the format MM/DD/YYYY how do I tell the control file to load it into the database as YYYYMM?
When you specify the columns in the INFILE declare just identify the format the data is held in. Like this load data infile 'whatever.csv' into table t23 fields terminated by ',' trailing nullcols ( col_1 integer , col_2 char , col_3 date "MM/DD/YYYY" , col_4 date "MM/DD/YYYY" , col_5 char ) Don't worry about the "to" date format. That is only for display purposes. Oracle stores dates in its own internal representation.
Are you trying to load the MM/DD/YYYY data into a char/varchar2 field, or into a date field? If you're trying to load it into a date field and you want to preserve the day of the month, APC's answer is correct. You can always just present the YYYYMM if that's what you want to do. If you're trying to load it into a date field and you want to truncate it to the first day of the month, I think something like this would work: date_column date "MM/DD/YYYY" "trunc(:date_column, 'mm')" If inserting into a CHAR/VARCHAR2 column, you'd could to transform it a little differently: vc2_column char "substr(:vc2_column, 7, 4) || substr(:vc2_column, 1, 2)"
hive date & time stamp from unix_timestamp()
I need two columns to be inserted with current date(sysdate) and time stamp. I have created the table and inserting data using unix_timestamp. I am not able to convert into hive date and time stamp format. ############ Hive create table ############# create table informatica_p2020.M23_MD_LOC_BKEY( group_nm string, loc string, natural_key string, loc_sk_id int, **load_date date, load_time timestamp)** ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' STORED AS TEXTFILE LOCATION '/user/spanda20/informatica_p2020/infor_external/m23_md_loc/m23_md_loc_bkey/'; ############### Insert into Table ########## insert overwrite table M23_MD_LOC_BKEY select 'M23' as group_nm,loc,concat('M23','|','LOC') as NATURAL_KEY, ROW_NUMBER() OVER () as loc_sk_id, from_unixtime(unix_timestamp(), 'YYYY-MM-DD'), from_unixtime(unix_timestamp(), 'YYYY-MM-DD HH:MM:SS.SSS') from M23_MD_LOC LIMIT 2 ; ################output of the insert query ############ M23 SY_BP M23|LOC 1 **2015-07-183** 2015-07-**183** 16:07:00.000 M23 SY_MX M23|LOC 2 2015-07-183 2015-07-183 16:07:00.000 Regards Sanjeeb
instead of from_unixtime(unix_timestamp(), 'YYYY-MM-DD') try - from_unixtime(unix_timestamp(), 'yyyy-MM-dd')
Setting the Date Format in the SQL*Loader Control File
I have csv file that has "17 September, 2009 11:06:06 AM" as COMPLETED_ON variable I am using sql loader to load data to oracle with folowing: LOAD DATA INFILE 'c:/load/file_name.csv' APPEND INTO TABLE tbl_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ( COMPLETED_ON DATE "not sure what to put here", ) in oracle I have this column created as follows: "COMPLETED_ON" TIMESTAMP (0) WITH LOCAL TIME ZONE How do I change COMPLETED_ON date in control file?
I'm not 100% with the LOAD DATA INFILE syntax, but I know the format string 'DD Month, YYYY HH:MI:SS AM' matches your date format. I was able to use it in a TO_DATE to convert your sample date. Try this: LOAD DATA INFILE 'c:/load/CW_COMPLIANCE.csv' APPEND INTO TABLE tbl_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ( COMPLETED_ON DATE 'DD Month, YYYY HH:MI:SS AM', )