Identifier is too long while loading from SQL*Loader - oracle

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 ""
)

Related

Passing shell variable in hive script

I am running hive script using shell job, with passing some parameters.
CREATE EXTERNAL TABLE IF NOT EXISTS db_${hivevar:myEnv}_travail.tble91_formation_eligible(
ID_FORM_ELIG BIGINT,
LIBELLE_COURT_FORM VARCHAR(50),
DEBUT_VALID_FORM TIMESTAMP,
FIN_VALID_FORM TIMESTAMP,
CODE_BRANCHE_FORM VARCHAR(4),
CODE_REGION_FORM VARCHAR(3),
CODE_PUBLIC_FORM VARCHAR(1),
ETAT_FORM VARCHAR(3),
DATE_CREAT_FORM TIMESTAMP,
ORIGINE_CREAT_FORM VARCHAR(20),
DATE_MAJ_FORM TIMESTAMP,
ORIGINE_MAJ_FORM VARCHAR(20),
ID_LISTE_ELIG BIGINT,
LIBELLE_FORMATION VARCHAR(255),
CODE_DIPLOME INT,
NUMERO_FORMATION VARCHAR(50),
CODE_REFERENTIEL VARCHAR(50) COMMENT 'Code associé au type de référentiel (ex: RNCP, RS, ELU, CPF, ...)',
CODE_RECONNAISSANCE VARCHAR(50)COMMENT 'Code de la reconnaissance (ex: RNCP1234, ELU134444, ...)',
NIVEAU_CONTROLE_HABILITATION VARCHAR(50) COMMENT 'Niveau de contrôle d\'habilitation d\'une reconnaissance éligible CPF (informatif, bloquant, absent)'
)
PARTITIONED BY TO_DATE('${hivevar:date_archive}')
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\001'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE
LOCATION '/${hivevar:myEnv}/ep/traitement/le5/app_db/db_${hivevar:myEnv}_le5_travail.db/tble91_formation_eligible/';
The problem is about passing the date_archive as a partition column, it'is sourced from shell script as String, but I wanna convert it as a date column, so that I used TO_DATE function.
For information, date_archive has many date values like : 2022-02-03
But, this make a problem
Error: Error while compiling statement: FAILED: ParseException line
22:15 extraneous input 'TO_DATE' expecting ( near '(' in create table
partition specification (state=42000,code=40000)
I tried :
BY (TO_DATE('${hivevar:date_archive}'))
BY (TO_DATE("${hivevar:date_archive}"))
BY (date_archive=TO_DATE("${hivevar:date_archive}"))
But always, I have errors, Any help, please ? Thank you

Not able to set default value in sqlloader

I am trying to load default value using sqlloader from a unix box, while my file only contains one column.
Below is my table structure:
CREATE TABLE DATA_LOAD(
SEQUENCE_NUMBER NUMBER(15)
CONSTRAINT SEQUENCE_NUMBER NOT NULL,
Account NUMBER(12)
CONSTRAINT Account NOT NULL,
SYS_CREATION_DATE DATE NOT NULL,
SYS_UPDATE_DATE DATE ,
OPERATOR_ID NUMBER(9) ,
APP_ID CHAR(6),
SERVICE_CODE CHAR(5) NOT NULL,
UPDATE_STAMP NUMBER(4),
ACCOUNT_TYPE CHAR(1),
ACCOUNT_SUB_TYPE CHAR(1),
STATUS VARCHAR2(2),
OPER_IND CHAR(1),
ERROR_REASON VARCHAR2(240)
)
File will contain only:
123476810
and I am trying to load with
LOAD DATA
INFILE '$INPUT_FILE'
INTO TABLE DATA_LOAD
FIELDS TERMINATED BY '$'
TRAILING NULLCOLS
(
Account,
SEQUENCE_NUMBER default 2,
STATUS default R,
OPER_IND default N,
SERVICE_CODE default abcde,
SYS_CREATION_DATE default to_date(sysdate,'DD-MON-YY')
)
getting this error:
SQL*Loader-350: Syntax error at line 9.
Expecting "," or ")", found "default".
SEQUENCE_NUMBER default 2,
Your syntax seems to be wrong. You need to be using CONSTANT
OPER_IND CONSTANT "N"

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')"
)

ORA-01722: invalid number with to_char timestamp

First, the table I'm trying to insert into is this table:
CREATE TABLE Message
(
MessageID varchar2(80) NOT NULL,
Message varchar2(500),
SendDate date NOT NULL,
SendID varchar2(50) NOT NULL,
Request_ID varchar2(50) NOT NULL,
PRIMARY KEY (MessageID)
);
and my insert query is this(Spring, mybatis):
INSERT INTO message (
messageid
, message
, senddate
, sendId
, request_Id
)VALUES(
#{sendidjbuser} + TO_CHAR(systimestamp, 'yyyymmddhh24missff3')
, #{message}
, sysdate
, #{sendidjbuser}
, #{requestIdjbuser}
)
I tried this on cmd and this part of the above query was the problem:
INSERT INTO message (messageId) VALUES('sendId' + TO_CHAR(systimestamp, 'yyyymmddmissff3'))
I'm on Oracle 11. I just tried inserting only TO_CHAR(systimestamp, 'yyyymmddmissff3') without adding that to a string and it worked. But I do need that part to work. Is there a right way to do that?
In Oracle, please use || or CONCAT() function to concatenate strings. You are using '+', hence getting the error.

load decimal into oracle table with sql loader

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

Resources