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"
Related
I have a table with several columns, like this:
CREATE TABLE CRM.INFO_ADICIONAL
(
ID_INFO_ADICIONAL NUMBER(10) NOT NULL,
NOMBRE VARCHAR2(100 BYTE) NOT NULL,
OBLIGATORIO NUMBER(1) NOT NULL,
TIPO_DATO VARCHAR2(2 BYTE) NOT NULL,
ACTIVO NUMBER(1) NOT NULL,
ID_TIPO_REQUERIMIENTO NUMBER(10) NOT NULL,
ID_USUARIO_AUDIT NUMBER(10) NOT NULL,
ORDEN NUMBER(3) DEFAULT 1,
RECHAZO_POR_NO NUMBER(1),
ID_TIPO_ARCHIVO_ADJUNTO NUMBER(10),
SOLICITAR_EN VARCHAR2(30 BYTE),
ID_CONSULTA NUMBER(10),
COMBO_ID VARCHAR2(40 BYTE),
APLICAR_COMO_VENC NUMBER(1),
MODIFICABLE NUMBER(1) DEFAULT 0,
ID_AREA_GESTION NUMBER(10),
ID_TAREA NUMBER(10)
)
The "COMBO_ID" column is the target. It is defined as VARCHAR, but when I'm trying to insert a row, TOAD displays
"ORA-06502: PL/SQL: error : error de conversión de carácter a número
numérico o de valor"
Or a 'numeric conversion error', in english.
This table have some pre-existing data, and I even found some rows including values at COMBO_ID column, all of them being VARCHAR, i.e.:
NACION (Nation), SEXO (Sex), etc
I tried a few simple SELECT statements
SELECT
ID_INFO_ADICIONAL,
NOMBRE,
OBLIGATORIO,
TIPO_DATO,
ACTIVO,
ID_TIPO_REQUERIMIENTO,
ID_USUARIO_AUDIT,
ORDEN,
RECHAZO_POR_NO,
ID_TIPO_ARCHIVO_ADJUNTO,
SOLICITAR_EN,
COMBO_ID,
APLICAR_COMO_VENC,
ID_CONSULTA,
MODIFICABLE,
ID_AREA_GESTION,
ID_TAREA
INTO
pRegistro
FROM
crm.info_adicional
where pRegistro is declared as
pRegistro INFO_ADICIONAL%ROWTYPE;
Again, I'm still getting this 'numeric conversion error'.
But, wait, if I hardcode the SELECT value in COMBO_ID column with a NUMBER:
SELECT
--other columns
123456 COMBO_ID,
--other columns
INTO
pRegistro
FROM
crm.info_adicional
It works, what the heck, it's defined as VARCHAR.
If I do the same but harcoding a string, it fails to execute again
Already tried in my DEV environment, and it's working fine.
I'm not a pro in Oracle, but I feel pretty lost.
Could it be that tables get "confused"?
Any clues?
That error can also be raised if you try to push a character string that is longer than your VARCHAR2's capacity (40 in your case).
Try to check if all the data you are trying to insert is correct :
SELECT
COMBO_ID
FROM
crm.info_adicional
ORDER BY length(COMBO_ID) desc;
That would also explain why it works fine on your DEV environment which, I suppose, has different data.
Okay, I already found the answer.
Quoting Oracle Documentation:
The %ROWTYPE attribute provides a record type that represents a row in a table or view. Columns in a row and corresponding fields in a record have the same names and datatypes.
So, basically, the SELECT statement needed to be in the same order as the table columns definition.
In my case, I had a few columns (including COMBO_ID) in a different order.
Tried, re-ordering, and works like a charm.
Thank you all for the support.
CREATE TABLE MAJEST_PROD_2015(
PRODUCT_ID CHAR(10) NOT NULL,
DESCRIPTION_PROD CHAR(30),
SEW_DATE DATE,
HARVEST_DATE DATE,
QUANTITY INT,
PROD_RATING INT(1),
PRIMARY KEY (PRODUCT_ID)
);
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Oracle is not MySQL so there is no INT(1) type:
CREATE TABLE MAJEST_PROD_2015(
PRODUCT_ID CHAR(10) NOT NULL,
DESCRIPTION_PROD CHAR(30),
SEW_DATE DATE,
HARVEST_DATE DATE,
QUANTITY INT,
PROD_RATING INT, -- here
PRIMARY KEY (PRODUCT_ID)
);
SqlFiddleDemo
If you don't need constant size of string, consider using VARCHAR2(30).
EDIT:
but i need those values to be between 1-5
So add check constraint:
CONSTRAINT chk_PROD_RATING CHECK (PROD_RATING BETWEEN 1 AND 5),
SqlFiddleDemo2
As already noted INT does not take a length constraint in Oracle - instead you could use NUMBER(1,0) which would restrict it to a single digit (-9 .. +9) and then you can further restrict it using a CHECK constraint.
CHAR(n) will also right pad the value with space (CHR(32)) characters so that it always contains the maximum number of characters. If you did not intend this then you should be using VARCHAR2(n) instead.
You also do not need a NOT NULL constraint on a column that is the PRIMARY KEY.
CREATE TABLE MAJEST_PROD_2015(
PRODUCT_ID VARCHAR2(10) CONSTRAINT MAJEST_PROD_2015__PROD_ID__PK PRIMARY KEY,
DESCRIPTION_PROD VARCHAR2(30),
SEW_DATE DATE,
HARVEST_DATE DATE,
QUANTITY INT,
PROD_RATING NUMBER(1,0) CONSTRAINT MAJEST_PROD_2015__PROD_RAT__CK CHECK ( PROD_RATING BETWEEN 1 AND 5 )
);
(also, should it be SEW_DATE or SOW_DATE? Since the next line talks about harvest then I would have thought "sow" was more apt.)
I cannot figure out the syntax issue with the following code. When I run it, I get error
ORA-00907: missing right parenthesis
Can anyone point out my flaw please?
CREATE OR REPLACE VIEW LATESTAPPLICATIONS AS
SELECT *
FROM application_history
WHERE entry_time IN
(SELECT entry_time
FROM application_history
GROUP BY application_number; )
ORDER BY entry_number;
Here is the table definition for application_history. I ideally want to only view application numbers with the latest time-stamps.
CREATE TABLE "APPLICATION_HISTORY"
( "ENTRY_NUMBER" NUMBER(28,0),
"APPLICATION_NUMBER" NUMBER(16,0) CONSTRAINT "APP_NUM_NN" NOT NULL ENABLE,
"ACTIVE" CHAR(1) DEFAULT 0 CONSTRAINT "ACTIVE_NN" NOT NULL ENABLE,
"STATUS" VARCHAR2(40) DEFAULT 'APPLICATION ENTERED' CONSTRAINT "STATUS_NN" NOT NULL ENABLE,
"DATE_APPROVED" DATE,
"DATE_APPLIED" DATE DEFAULT SYSDATE CONSTRAINT "DATE_APPLIED_NN" NOT NULL ENABLE,
"ENTRY_TIME" TIMESTAMP (6) DEFAULT SYSDATE,
CONSTRAINT "ENTRY_NUM_PK" PRIMARY KEY ("ENTRY_NUMBER")
USING INDEX ENABLE
)
You have a semi-colon at the last but 1 line. GROUP BY application_number; ) Remove it and you should be fine.
Semi-colon acts as the query terminator in Oracle, as you had placed it before the ) Oracle could not find it.
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 ""
)
I was loading data using SQL*Loader and when making the control file I used the table definition and accidentally left the INTEGER data type on the "version" line.
And in the "version" field (data type integer) it inserted the value 808594481.
I'm having a hard time understanding how it processed this value -- I'm assuming it took it as a literal ... but is that the sum of the ASCII representations of each letter?
NOPE!
SELECT ASCII('I')+ascii('N')+ASCII('T')+ASCII('E')+ASCII('G')+ASCII('E')+ASCII('G')+ASCII('E')+ASCII('R')
FROM SYS.DUAL
returns 666 (which, btw is hilarious).
concatenate ascii values?
SELECT ASCII('I')||ascii('N')||ASCII('T')||ASCII('E')||ASCII('G')||ASCII('E')||ASCII('G')||ASCII('E')||ASCII('R')
FROM SYS.DUAL
returns 737884697169716982
I'm hoping someone out there knows the answer.
This is the actual control file:
OPTIONS (SKIP=1)
LOAD DATA
APPEND into table THETABLE
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(id ,
parent_id ,
record_id ,
version INTEGER,
created_at ,
updated_at ,
created_by ,
updated_by ,
species_and_cohort ,
species_and_cohort_count)
Table DDL:
create table THETABLE
(
id VARCHAR2(36),
parent_id VARCHAR2(36),
record_id VARCHAR2(36),
version INTEGER,
created_at VARCHAR2(25),
updated_at VARCHAR2(25),
created_by VARCHAR2(50),
updated_by VARCHAR2(50),
species_and_cohort VARCHAR2(150),
species_and_cohort_other VARCHAR2(150),
species_and_cohort_count NUMBER
)
Data:
id,parent_id,record_id,version,created_at,updated_at,created_by,updated_by,species_and_cohort,species_and_cohort_other,species_and_cohort_count
60D90F54-C5F2-47AF-951B-27A424EAE8E3,f9fe8a3b-3470-4caf-b0ba-3682a1c79731,f9fe8a3b-3470-4caf-b0ba-3682a1c79731,1,2014-09-23 21:02:54 UTC,2014-09-23 21:02:54 UTC,x#gmail.com,x#gmail.com,"PRCA Cherrylaurel,Sapling","",5
FC6A2120-AA0B-4238-A2F6-A6AEDD9B8202,f9fe8a3b-3470-4caf-b0ba-3682a1c79731,f9fe8a3b-3470-4caf-b0ba-3682a1c79731,1,2014-09-23 21:03:02 UTC,2014-09-23 21:03:02 UTC,x7#gmail.com,x7#gmail.com,"JUVI Eastern Redcedar,Sapling","",45
If you split 808594481 into bytes as it would be encoded in a 32 bit twos complement encoding, and treat each byte as an ascii-encoded character, you get "02,1" or "1,20" depending on byte order. You probably inserted a string that starts or ends with one of those, and some layer between your code and the database silently converted it to an integer.